Mic*_*ick 8 python azure azure-storage azure-blob-storage
我正在使用 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)
Run Code Online (Sandbox Code Playgroud)
这是有效的,但 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)
Run Code Online (Sandbox Code Playgroud)