上载到Azure Blob存储时设置内容类型 [英] Set content type when uploading to Azure Blob Storage
本文介绍了上载到Azure Blob存储时设置内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Azure Blob存储客户端库上传静态站点.
I am uploading a static site using the Azure Blob storage client library.
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
.
This is working but the HTML file is downloading instead of displaying. This is because the content type is wrong: Content-Type: application/octet-stream
.
有什么方法可以使用 upload_blob
进行设置吗?
Is there any way to set this using upload_blob
?
更新:
要使其正常工作,我需要这样做:
To get this working, I needed this:
my_content_settings = ContentSettings(content_type='text/html')
blob_client.upload_blob(data, overwrite=True, content_settings=my_content_settings)
推荐答案
查看代码 ContentSettings
.您可以在那里定义 content_type
.
Looking at the code here
, one of the parameters to this method is content_settings
which is of type ContentSettings
. You can define content_type
there.
这篇关于上载到Azure Blob存储时设置内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文