Python azure 上传文件内容类型更改为 application/octet-stream

Sho*_*jaz 0 python azure

我正在使用 python Azure sdk。当文件上传时,其内容类型更改为 application/octet-stream。

我想为 PNG 图像设置其默认内容类型,如image/png

我正在使用以下方法上传文件put_block_blob_from_path()

有没有办法保留默认内容类型?谢谢

Ber*_*rst 5

您可以像这样显式设置 content-type 属性:

from azure.storage.blob import ContentSettings

block_blob_service.create_blob_from_path(
    'mycontainer',
    'myblockblob',
    'mypngimage.png',
    content_settings=ContentSettings(content_type='image/png')
)
Run Code Online (Sandbox Code Playgroud)

来源:https : //docs.microsoft.com/en-us/azure/storage/blobs/storage-python-how-to-use-blob-storage