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 のコンテンツ タイプを設定します。
Blob に保存されているメディア ファイルの Content-type を設定する