[英]Set content type when uploading to Azure Blob Storage
I am uploading a static site using the Azure Blob storage client library.我正在使用 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)
This is working but the HTML file is downloading instead of displaying.这是有效的,但 HTML 文件正在下载而不是显示。 This is because the content type is wrong:
Content-Type: application/octet-stream
.这是因为内容类型错误:
Content-Type: application/octet-stream
。
Is there any way to set this using upload_blob
?有没有办法使用
upload_blob
设置它?
Update:更新:
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)
Looking at the code here
, one of the parameters to this method is content_settings
which is of type ContentSettings
.查看
here
的代码,此方法的参数之一是content_settings
,它的类型为ContentSettings
。 You can define content_type
there.您可以在那里定义
content_type
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.