gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 15:42:39 25 4
gpt4 key购买 nike

如果我尝试覆盖现有的Blob,请执行以下操作:

blob_client = BlobClient.from_connection_string(connection_string, container_name, blob_name)
blob_client.upload_blob('Some text')

我得到 ResourceExistsError

我可以检查Blob是否存在,将其删除,然后上传:
try:
blob_client.get_blob_properties()
blob_client.delete_blob()
except ResourceNotFoundError:
pass
blob_client.upload_blob('Some text')

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

最佳答案

从这个issue看来,您可以将overwrite=True添加到upload_blob中,它将起作用。

关于python - 在Python中覆盖Azure Blob的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61130890/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com