Azure文件存储内容类型始终为应用程序/八位字节流 [英] Azure File storage content-type is always application/octet-stream

查看:76
本文介绍了Azure文件存储内容类型始终为应用程序/八位字节流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用

I'm currently having issue with Azure File storage when I build up a URL with a shared access signature (SAS) Token. The file will download in the browser, but the content-type is always application/octet-stream rather than changing to match the mime type of the file. If I put the file in Azure BLOB storage and build up a URL with a SAS Token, it sends the correct content-type for my file (image/jpeg).

我认为这是问题所在,但已将存储帐户从V1升级到V2,但是并不能解决问题.

I've upgraded my storage account from V1 to V2 thinking that was the problem, but it didn't fix it.

有人知道我可以尝试做些什么,以使Azure文件存储能够使用带有SAS令牌的URL返回正确的内容类型来下载文件吗?

Does anyone have a clue what I could try that might get Azure File storage to return the correct content-type using a URL with SAS Token to download the file?

推荐答案

如果未提供任何内容,则Azure Blob会降至"application/octet-stream"的默认值.为了获得正确的模仿类型,这是我对烧瓶应用程序所做的:

Azure blob falls to the default value of 'application/octet-stream' if nothing is provided. To get the correct mimetypes, this is what I did with my flask app:

@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))
            except Exception as e:
                print (str(e))
                pass

mime_type已传递到ContentSettings,以获取上传到天蓝色blob的文件的当前mimetypes.

mime_type was passed to ContentSettings to get the current mimetypes of files uploaded to azure blob.

在nodeJS中:

blobService.createBlockBlobFromStream(容器,blob,流,streamLength,{contentSettings:{contentType:fileMimeType}},回调)

其中:

fileMimeType 是要上传的文件的类型

fileMimeType is the type of the file being uploaded

回调是您的回调实现

所用方法的参考: 查看全文

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆