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

标签 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)

这可以工作,但 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)

最佳答案

查看代码here ,此方法的参数之一是 content_settings ,其类型为 ContentSettings 。您可以在那里定义content_type

关于python - 上传到 Azure Blob 存储时设置内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59752380/

相关文章:

c# - 无法启动 WebJob - "Azure Storage Emulator is not supported"

azure - 基本 Azure 存储入门。创建计划文件备份

azure-storage - 为什么 Azure 存储队列上的 ApproximateMessageCount 属性可以为空?

python - Statsmodels 无法导入模块

java - AWS Lambda 环境中 javac、jar 等二进制文件位于哪个路径?

python - sklearn 树可视化中的这些列表是什么

使用 ARM 的 Azure Blob 存储容器存储访问策略

python - pysftp,paramiko,请求 : Error reading SSH protocol banner

Azure Maps 路线方向错误返回错误请求

使用 xml Spring 与 Azure blob 存储集成