I am using Microsoft Azure SDK for Python in project. I want to move or copy Blob from one container to another. for exmaple
https://demostorage.blob.core.windows.net/image-container/pretty.jpg
I want to move this blob to
https://demostorage.blob.core.windows.net/demo-container/
I have found following method in python SDK but unable to understand it.
def copy_blob(self, container_name, blob_name,...):
How can I do this? Thank you
Advertisement
Answer
I have done in this way.
from azure.storage.blob import BlobService
def copy_azure_files(self):
blob_service = BlobService(account_name='account_name', account_key='account_key')
blob_name = 'pretty.jpg'
copy_from_container = 'image-container'
copy_to_container = 'demo-container'
blob_url = blob_service.make_blob_url(copy_from_container, blob_name)
# blob_url:https://demostorage.blob.core.windows.net/image-container/pretty.jpg
blob_service.copy_blob(copy_to_container, blob_name, blob_url)
#for move the file use this line
blob_service.delete_blob(copy_from_container, blob_name)
I have not found any Blob Move method yet. So I have used the copy method and then execute Blob function.
This is my solution. If you have better way to handle all this please share with me.
Note: I have not used any custom method all these methods are included in SDK.