blob.Properties.ContentType = "application/pdf";
//通過擴展
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;
}
使用此設置BLOB的內容類型,同時節省它獲取文件的內容類型。
Set Content-type of media files stored on Blob
的網址不再有效 – spuder 2017-03-01 18:08:40