How To Upload Files To Azure Blob Storage?
Solution 1:
If you're using python, I would suggest using the azure python sdk to do your uploading. You can see more from this example here...
https://github.com/Azure-Samples/storage-blobs-python-quickstart/blob/master/example.py
It can be as quick as this (from the quick start docs : https://docs.microsoft.com/en-us/python/api/overview/azure/storage?view=azure-python) to interface with your azure blob storage account. Just put in some logic to loop through a directory recursively and upload each file.
First make sure to pip install the required packages, and then grab your account name (blob storage name) and your access key from the portal...plug them in and you're good to go.
pip install azure-storage-blob azure-mgmt-storage
Then write some python code here...
from azure.storage.blob import BlockBlobService, PublicAccess
blob_service = BlockBlobService('[your account name]','[your access key]')
blob_service.create_container(
'mycontainername',
public_access=PublicAccess.Blob
)
blob_service.create_blob_from_bytes(
'mycontainername',
'myblobname',
b'hello from my python file'
)
print(blob_service.make_blob_url('mycontainername', 'myblobname'))
This should get you going in the right direction pretty quickly.
Solution 2:
The issue you're seeing for SAS is actually working as it's supposed to. SAS has an expiration date, and can be revoked at anytime you want. So you'll be required to use the new one as soon as it is available.
I'd recommend using the python SDK since it uses the Storage Key and Account name, which doesn't expire, except when a key is rotated. I wrote a few tools/Samples in python SDK which performs all actions: List, Upload and delete: https://github.com/adamsmith0016/Azure-storage
Feel free to clone and re-use any code.
Post a Comment for "How To Upload Files To Azure Blob Storage?"