Nic*_*sen 26 firefox google-chrome blob azure azure-storage
在我们的应用程序中,我们为用户提供了将文档上传到windows azure blob存储帐户的能力.上传文档或图像后,它会被分配一些网址(https://name.blob.core.windows.net/container/file-name.jpg).如果文档是图像或pdf或某些可由浏览器呈现的文件,我们试图在浏览器中显示它而无需用户下载文件.如果我们只是打开一个新窗口或选项卡并将用户引导到IE中的blob uri,则图像或pdf会在浏览器中正确呈现.但是,如果我们尝试在Chrome,FireFox或Safari中打开一个指向uri的新窗口,它只会下载文件而不是在浏览器中显示它.
有没有办法强制后三个浏览器只显示文件而不是下载它?
sud*_*u63 25
blob.Properties.ContentType = "application/pdf";
Run Code Online (Sandbox Code Playgroud)
//按扩展名获取文件的内容类型
public static string GetFileContentType(string FilePath)
{
string ContentType = String.Empty;
string Extension = Path.GetExtension(FilePath).ToLower();
switch (Extension)
{
case ConstantUtility.FILE_EXTENSION_PDF:
ContentType = "application/pdf";
break;
case ConstantUtility.FILE_EXTENSION_TXT:
ContentType = "text/plain";
break;
case ConstantUtility.FILE_EXTENSION_BMP:
ContentType = "image/bmp";
break;
case ConstantUtility.FILE_EXTENSION_GIF:
ContentType = "image/gif";
break;
case ConstantUtility.FILE_EXTENSION_PNG:
ContentType = "image/png";
break;
case ConstantUtility.FILE_EXTENSION_JPG:
ContentType = "image/jpeg";
break;
case ConstantUtility.FILE_EXTENSION_JPEG:
ContentType = "image/jpeg";
break;
case ConstantUtility.FILE_EXTENSION_XLS:
ContentType = "application/vnd.ms-excel";
break;
case ConstantUtility.FILE_EXTENSION_XLSX:
ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
break;
case ConstantUtility.FILE_EXTENSION_CSV:
ContentType = "text/csv";
break;
case ConstantUtility.FILE_EXTENSION_HTML:
ContentType = "text/html";
break;
case ConstantUtility.FILE_EXTENSION_XML:
ContentType = "text/xml";
break;
case ConstantUtility.FILE_EXTENSION_ZIP:
ContentType = "application/zip";
break;
default:
ContentType = "application/octet-stream";
break;
}
return ContentType;
}
Run Code Online (Sandbox Code Playgroud)
使用此选项可在保存时设置blob的内容类型.
| 归档时间: |
|
| 查看次数: |
9185 次 |
| 最近记录: |