I am using Microsoft Azure SDK for Python in project. I want to move or copy Blob from one container to another. for exmaple
JavaScript
x
2
1
https://demostorage.blob.core.windows.net/image-container/pretty.jpg
2
I want to move this blob to
JavaScript
1
2
1
https://demostorage.blob.core.windows.net/demo-container/
2
I have found following method in python SDK but unable to understand it.
JavaScript
1
2
1
def copy_blob(self, container_name, blob_name, ):
2
How can I do this? Thank you
Advertisement
Answer
I have done in this way.
JavaScript
1
17
17
1
from azure.storage.blob import BlobService
2
3
def copy_azure_files(self):
4
5
blob_service = BlobService(account_name='account_name', account_key='account_key')
6
blob_name = 'pretty.jpg'
7
copy_from_container = 'image-container'
8
copy_to_container = 'demo-container'
9
10
blob_url = blob_service.make_blob_url(copy_from_container, blob_name)
11
# blob_url:https://demostorage.blob.core.windows.net/image-container/pretty.jpg
12
13
blob_service.copy_blob(copy_to_container, blob_name, blob_url)
14
15
#for move the file use this line
16
blob_service.delete_blob(copy_from_container, blob_name)
17
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.