我正在使用python Azure sdk。当文件上传时,其内容类型更改为application / octet-stream。
我想为PNG图像设置默认内容类型,例如 image / png 。
我使用以下方法上传文件 put_block_blob_from_path()
有没有办法保留默认内容类型?感谢
答案 0 :(得分:2)
您可以像这样显式设置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')
)
来源: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-python-how-to-use-blob-storage
答案 1 :(得分:0)
如果未提供任何内容,则Azure Blob会降至“ application / octet-stream”的默认值。为了获得正确的模仿类型,这是我对烧瓶应用程序所做的:
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
mime_type = f.content_type
print (mime_type)
print (type(f))
try:
blob_service.create_blob_from_stream(container, f.filename, f,
content_settings=ContentSettings(content_type=mime_type))
mime_type已传递到ContentSettings,以获取上传到天蓝色blob的文件的当前mimetypes。