Storage accounts is one of the services in Microsoft Azure that provides cloud storage, where massive amounts of unstructured data can be stored. Unstructured data could be an image, text, video, or any binary data that doesn't adhere to a particular data model or definition.
In simple terms, a storage account is a place where you can store files in Azure and organize the files inside that container. Azure Blob Storage includes any number of containers – each of the containers in turn can store any number of blobs.
Do you have an Azure account created? If yes, proceed with the steps below to create an Azure storage account. If not, first create a free account using the link https://azure.microsoft.com/en-us/free and then continue.
Given below are the steps to create a storage account and the container inside it – via the Azure portal:
This is typically what you’d want to do next. Here’s how you go about it.
After creating a storage account and a container, it’s important to know the different approaches through which the Azure Cloud Blob Containers can be accessed. Worry not! Here’s a rundown of each approach:
Do you have an Azure account created? And have you already created the subscription and container inside it? Then you’re on the right path, and you can start following the below approaches:
az storage blob upload \ --account-name\ --container-name \ --name myFile.txt \ --file myFile.txt \ --auth-mode login
az storage blob list \ --account-name\ --container-name \ --output table \ --auth-mode login
How can you access the blob storage if you don’t have Azure credentials, but have only the Account name and Account key?
No problem! You can still view and access the blobs. In fact, there are a few approaches to do so.
Given below are the approaches for you to continue with:
If you have the Python 3.6+ version and want to access the files from the python script, you are at the right place!
from azure.storage.blob import BlobServiceClient storage_account_key = "ACCOUNT_KEY” storage_account_name = "ACCOUNT_NAME" connection_string = "DefaultEndpointsProtocol=http;AccountName=ACCOUNT_NAME;AccountKey=ACCOUNT_KEY;BlobEndpoint=http://127.0.0.1:10000/ACCOUNT_NAME;QueueEndpoint=http://127.0.0.1:10001/ ACCOUNT_NAME;TableEndpoint=http://127.0.0.1:10002/ACCOUNT_NAME" container_name = "CONTAINER_NAME" def uploadFileToBlobStorage(file_path,file_name): blob_service_client = BlobServiceClient.from_connection_string(connection_string) blob_client = blob_service_client.get_blob_client(container=container_name, blob=file_name) with open(file_path,"rb") as data: blob_client.upload_blob(data) print(f"{file_name} Uploaded Successfully.") uploadFileToBlobStorage("FILE_PATH_FROM_YOUR_SYSTEM","FILE_PATH_OF_AZURE_STORAGE_BLOB")
connection_string = "DefaultEndpointsProtocol=http;AccountName=ACCOUNT_NAME;AccountKey=ACCOUNT_KEY;BlobEndpoint=http://127.0.0.1:10000/ACCOUNT_NAME;QueueEndpoint=http://127.0.0.1:10001/ ACCOUNT_NAME;TableEndpoint=http://127.0.0.1:10002/ACCOUNT_NAME" container_name = "CONTAINER_NAME" service = BlobServiceClient.from_connection_string(conn_str=connection_string) from azure.storage.blob import ContainerClient container = ContainerClient.from_connection_string(conn_str=connection_string, container_name="CONTAINER_NAME") blob_list = container.list_blobs() for blob in blob_list: print(blob.name + '\n')
If you have the 5.6+ version of PHP and want to access the files from the PHP script, just follow these steps
{ "require": { "microsoft/azure-storage-file": "*" } }
createBlobService($connectionString); $content = fopen("FILE_TO_UPLOAD", "r"); $blob_name = "BLOB_NAME"; try { //Upload blob $blobProxy->createBlockBlob("CONTAINER_NAME", $blob_name, $content); } catch(Exception $e){ $code = $e->getCode(); $error_message = $e->getMessage(); echo $code.": ".$error_message."
"; }
createBlobService($connectionString); try { // List blobs. $blob_list = $blobRestProxy->listBlobs("CONTAINER_NAME "); $blobs = $blob_list->getBlobs(); foreach($blobs as $blob) { echo $blob->getName().": ".$blob->getUrl()."
"; } } catch(Exception $e){ $code = $e->getCode(); $error_message = $e->getMessage(); echo $code.": ".$error_message."
"; }
It’s the end of the line for this comprehensive guide on Azure Blob Storage. Ideally, this article has helped you create and access the blobs in your Azure storage account.
In addition to the Azure services, Nalashaa also has expertise in multiple cloud engineering services, using platforms such as AWS, Google cloud platform, and more – across multiple industries. Reach out to our experts at info@nalashaa.com for more details and choose the path that suits you best.
Constantly looking to fuel personal and professional growth, I’m also a wordsmith, a reader, a sports lover, and a fitness enthusiast, who believes that learning via exploration and curiosity is growth's only true form. I use my free time to interact with people from different walks of life, and try to learn about anything under the sun.
Dynamics CRM integrated with SharePoint to deliver a simplified sales and marketing platform for a manufacturing giant