The goal of the project is to create a Blob Storage and upload some files onto it
Azure Blob Storage is a service provided by Microsoft Azure that allows you to store and manage large amounts of unstructured data, such as text and binary data. It is part of the Azure Storage suite and is designed to handle a variety of storage scenarios.
- Create a Azure Blob Storage on Azure Portal
https://portal.azure.com/#create/Microsoft.StorageAccount-ARM
-
Upload content through 3 different ways
from azure.identity import DefaultAzureCredential from azure.storage.blob import BlobServiceClient def upload_sample_data(credential: DefaultAzureCredential): # Connect to Blob Storage account_url = os.environ["AZURE_STORAGE_ACCOUNT_BLOB_URL"] blob_service_client = BlobServiceClient(account_url=account_url, credential=credential) container_client = blob_service_client.get_container_client(sample_container_name) if not container_client.exists(): container_client.create_container() sample_data_directory_name = os.path.join("data", "documents") sample_data_directory = os.path.join(os.getcwd(), sample_data_directory_name) for filename in os.listdir(sample_data_directory): with open(os.path.join(sample_data_directory, filename), "rb") as f: blob_client = container_client.get_blob_client(filename) if not blob_client.exists(): print(f"Uploading {filename}...") blob_client.upload_blob(data=f) print(f"Completed {filename}!")
How to get
AZURE_STORAGE_ACCOUNT_BLOB_URL
export AZURE_STORAGE_ACCOUNT=<storage_account_name> export AZURE_STORAGE_ACCOUNT_BLOB_URL=https://$AZURE_STORAGE_ACCOUNT.blob.core.windows.net/ echo $AZURE_STORAGE_ACCOUNT_BLOB_URL # https://readinggroupstorage.blob.core.windows.net/
- Using AzCopy (Documentation)
-
Download AzCopy Portable Binary (Download Link)
-
Extract the file
tar -xzvf azcopy_linux_amd64_10.25.1.tar.gz
-
Generate the Blob SAS URL
(Remember to give both
Read
andWrite
permissions whie generating the SAS URL) -
Copy the folder contents into the Storage
# cd to the folder which has the azcopy executable ./azcopy copy "/nfs/users/ext_tr_muhammad_salman/Azure_AI/azure-demo-project/demoStorage/Data/*" "https://readinggroupstorage.blob.core.windows.net/sample-container?sp=rw&st=2024-08-12T17:20:19Z&se=2024-08-31T01:20:19Z&sv=2022-11-02&sr=c&sig=Hak6U7cPBDlqvYM1jYh%2Fvpz5gNtpIUYVtGE6yTpBj58%3D" --recursive=true