The Python Oracle

Best way to overwrite Azure Blob in Python

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Magic Ocean Looping

--

Chapters
00:00 Best Way To Overwrite Azure Blob In Python
00:45 Accepted Answer Score 35
00:56 Answer 2 Score 0
01:26 Answer 3 Score 2
02:23 Thank you

--

Full question
https://stackoverflow.com/questions/6113...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #azureblobstorage

#avk47



ACCEPTED ANSWER

Score 35


From this issue it seems that you can add overwrite=True to upload_blob and it will work.




ANSWER 2

Score 2


If you upload the blob with the same name and pass in the overwrite=True param, then all the contents of that file will be updated in place.

   blob_client.upload_blob(data, overwrite=True)

During the update readers will continue to see the old data by default.(until new data is committed).

I think there is also an option to read uncommitted data as well if readers wish to.

Below from the docs:

overwrite (bool) – Whether the blob to be uploaded should overwrite the current data. If True, upload_blob will overwrite the existing data. If set to False, the operation will fail with ResourceExistsError. The exception to the above is with Append blob types: if set to False and the data already exists, an error will not be raised and the data will be appended to the existing blob. If set overwrite=True, then the existing append blob will be deleted, and a new one created. Defaults to False.




ANSWER 3

Score 0


The accepted answer might work, but is potentially incorrect according to documentation;

azure.storage.blob.ContainerClient.upload_blob() can take the parameter overwrite=True See docs for ContainerClient

The documentation for azure.storage.blob.BlobClient.upload_blob() does not document an overwrite parameter See docs for BlobClient