Python: How to move or copy Azure Blob from one container to another

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

September 10th, 2015 8:08am

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,copy_from_container)
        # 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, copy_from_container)

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.

Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 9:07am

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,copy_from_container)
        # 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, copy_from_container)

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.

September 10th, 2015 1:05pm

Hi,

Thanks for sharing your solution here, from my research, Azure storage is not natively support move, so your solution is a good choice, when you delete blob, please ensure the blob has been copied to another container.

Best Regards,

Jambor 

Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 10:52pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics