在 Python 中覆盖 Azure Blob 的最佳方法

Rob*_*man 6 python azure-blob-storage

如果我尝试覆盖现有的 blob:

blob_client = BlobClient.from_connection_string(connection_string, container_name, blob_name)
blob_client.upload_blob('Some text')
Run Code Online (Sandbox Code Playgroud)

我得到一个ResourceExistsError.

我可以检查 blob 是否存在,将其删除,然后上传:

try:
    blob_client.get_blob_properties()
    blob_client.delete_blob()
except ResourceNotFoundError:
    pass
blob_client.upload_blob('Some text')
Run Code Online (Sandbox Code Playgroud)

考虑到 python azure blob 存储 API 可用的内容以及惯用的 python 样式,是否有更好的方法来覆盖现有 blob 的内容?我期望有某种覆盖参数可以在upload_blob方法中选择性地设置为 true ,但它似乎不存在。

小智 14

从这个问题似乎可以添加overwrite=Trueupload_blob,它会工作。

  • 如果 Microsoft 记录他们的 API,那就太好了! (8认同)