问题
I have some images in a local folder on my windows machine. I want to upload all images to the same blob in the same container.
I know how to upload a single file with Azure Storage SDKs BlockBlobService.create_blob_from_path()
, but I do not see a possibility to upload all images in the folder at once.
However, the Azure Storage Explorer provides a functionality for this, so it must be possible somehow.
Is there a function providing this service or do I have to loop over all files in a folder and run create_blob_from_path()
multiple times for the same blob?
回答1:
There is no direct way to do this. You can go through the azure storage python SDK blockblobservice.py and baseblobservice.py for details.
As you mentioned, you should loop over it. The sample code as below:
from azure.storage.blob import BlockBlobService, PublicAccess
import os
def run_sample():
block_blob_service = BlockBlobService(account_name='your_account', account_key='your_key')
container_name ='t1s'
local_path = "D:\\Test\\test"
for files in os.listdir(local_path):
block_blob_service.create_blob_from_path(container_name,files,os.path.join(local_path,files))
# Main method.
if __name__ == '__main__':
run_sample()
The files in local:
After code execution, they are uploaded to azure:
来源:https://stackoverflow.com/questions/53227677/upload-multiple-files-from-folder-to-azure-blob-storage-using-azure-storage-sdk