【发布时间】:2020-05-02 06:39:06
【问题描述】:
我正在使用 Azure Blob 存储客户端库上传静态站点。
blob_service_client = BlobServiceClient.from_connection_string(az_string)
blob_client = blob_service_client.get_blob_client(container=container_name, blob=local_file_name)
print("\nUploading to Azure Storage as blob:\n\t" + local_file_name)
with open('populated.html', "rb") as data:
test = blob_client.upload_blob(data, overwrite=True)
这是可行的,但 HTML 文件正在下载而不是显示。这是因为内容类型错误:Content-Type: application/octet-stream。
有什么方法可以使用upload_blob 进行设置吗?
更新:
为了让它工作,我需要这个:
my_content_settings = ContentSettings(content_type='text/html')
blob_client.upload_blob(data, overwrite=True, content_settings=my_content_settings)
【问题讨论】:
-
更新正是我所需要的。谢谢米克!
-
感谢您的更新。试图在极其糟糕的文档中找到这一点浪费了一天时间。
-
你是如何导入
ContentSettings类的? -
@harvpan
from azure.storage.blob import BlobServiceClient, ContentSettings
标签: python azure azure-storage azure-blob-storage