问题描述
当我使用共享访问签名(SAS)令牌.该文件将在浏览器中下载,但是content-type始终是application/octet-stream,而不是进行更改以匹配该文件的mime类型.如果我将文件放入Azure BLOB存储中,并使用SAS令牌构建URL,它将为我的文件发送正确的内容类型(图像/jpeg).
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
回调
是您的回调实现
这篇关于Azure文件存储内容类型始终为应用程序/八位字节流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!