导航到URL时始终会下载Azure Blob [英] Azure Blob always downloads when navigating to url

查看:59
本文介绍了导航到URL时始终会下载Azure Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序中,我们为用户提供了将文档上传到Windows azure blob存储帐户的能力.上传文档或图像后,将为其分配一些URL(https://name.blob.core.windows.net/container/file-name.jpg).如果文档是浏览器可以渲染的图像或pdf或某些文件,我们试图在浏览器中显示它而不需要用户下载文件.如果我们只是打开一个新窗口或标签并将用户定向到IE中的Blob uri,则图像或pdf将在浏览器中正确呈现.但是,如果我们尝试在Chrome,FireFox或Safari中打开一个指向uri的新窗口,则它只会下载文件,而不是在浏览器中显示该文件.

In our application we give the user the abilty to upload a document to a windows azure blob storage account. After uploading the document or image it gets assigned some url (https://name.blob.core.windows.net/container/file-name.jpg). If the document is an image or a pdf or some file that can be rendered by the browser we are trying to display it in the browser without requiring the user to download the file. If we just open up a new window or tab and direct the user to the blob uri in IE, the image or pdf renders correctly in the browser. But, if we try to just open a new window pointing to the uri in Chrome, FireFox, or Safari, it just downloads the file instead of displaying it in the browser.

是否有一种方法可以强制后三个浏览器仅显示文件而不下载文件?

Is there a way to force the latter three browsers to just display the file instead of download it?

推荐答案

这是因为您没有设置

This is because you didn't set the content type property of the blob (the default is application/octet-stream, which triggers a download in most browsers). If you want PDF files to show correctly you'll need to change the content type of your PDF files to application/pdf (image/jpeg for jpeg files).

您可以使用Azure Storage Explorer,Cloud Storage Studio,CloudBerry,CloudXplorer等常用工具来更改内容类型,也可以使用SDK来更改内容类型.请注意,其中一些工具会在上传文件后自动将内容类型设置为正确的类型.

You can change the content type with common tools like Azure Storage Explorer, Cloud Storage Studio, CloudBerry, CloudXplorer, ... or by using the SDK. Note that some of these tools will automatically set the content type to the right one after uploading the file.

这篇关于导航到URL时始终会下载Azure Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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