0

I am using Microsoft Azure SDK for Python and I want to move or rename a Blob within the same container.

For example, how to move this blob

https://demostorage.blob.core.windows.net/container-a/folder1/file1.jpg

into this?

https://demostorage.blob.core.windows.net/container-a/folder2/file2.jpg
freedev
  • 25,946
  • 8
  • 108
  • 125
  • I think you can accomplish that by using the [`BlobClient.start_copy_from_url`](https://learn.microsoft.com/en-us/azure/developer/python/sdk/storage/azure-storage-blob/azure.storage.blob.blobclient?source=recommendations&view=storage-py-v12#start-copy-from-url-source-url--metadata-none--incremental-copy-false----kwargs-) method to copy from the source blob to the target, and then, deleting the source blob. – Oluwafemi Sule Oct 04 '22 at 06:22
  • @OluwafemiSule I agree, I'm trying to understand if there is a simpler way given that the file remain within the container. As far as I understood, the `start_copy_from_url` method still implements an asynchronous copy of the file (download/upload) – freedev Oct 04 '22 at 09:03

1 Answers1

0

After reproducing from my end I could able to achieve this using copy_blob of azure-storage versioned 0.20.0.

from azure.storage.blob import BlobService

accountName = "<YourAccountName>"
accountKey = "<YourAccountKey>"

blob_service = BlobService(accountName ,accountKey )
sourceFileName = 'file1.png'
destinationFileName = 'file2.png'
sourcePath = 'container1/folder1'
destinationPath = 'container1/folder2'

blob_url = blob_service.make_blob_url(sourcePath,sourceFileName)
blob_service.copy_blob(destinationPath, destinationFileName, blob_url)

enter image description here

SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18