简体   繁体   English

上传到 Azure Blob 存储时设置内容类型

[英]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.

相关问题 上传到 Azure Blob 存储时自动设置内容类型 - Set content type authomatically when uploading to Azure Blob Storage 将数组作为 .jpg 图像上传到 Azure blob 存储 - Uploading array as a .jpg image to Azure blob storage 使用 python 将文件上传到 azure blob 存储 - Uploading file to azure blob storage using python 在 azure blob 存储中设置文件上传限制 - Set file upload limit in azure blob storage 使用python上载csv文件以使Blob存储蔚蓝 - Uploading csv file using python to azure blob storage Microsoft Azure 计时器功能未将文件上传到 blob 存储 - Microsoft Azure Timer Function not uploading files to blob storage 在 Azure blob 存储中上传文件时出现 InvalidAuthenticationInfo 错误 - InvalidAuthenticationInfo error while uploading dcument in Azure blob storage 为什么将视频上传到 azure blob 存储这么慢? [江戈] - Why is uploading a video to azure blob storage this slow? [DJANGO] 使用 Databricks 将文件从 Azure Blob 存储上传到 SFTP 位置? - Uploading files from Azure Blob Storage to SFTP location using Databricks? Azure存储Python SDK:将文件上传到Azure Blob存储而不将其写在磁盘上 - Azure Storage Python SDK : Uploading file to Azure blob storage without writting it on my disk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM