コンテナー参照名 (つまり、BLOB 内のファイルの完全パス名) に基づいて、Azure BLOB からファイルをダウンロードするコントローラー アクションがあります。コードは次のようになります。
public FileContentResult GetDocument(String pathName)
{
try
{
Byte[] buffer = BlobStorage.DownloadFile(pathName);
FileContentResult result = new FileContentResult(buffer, "PDF");
String[] folders = pathName.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
// get the last one as actual "file name" based on some convention
result.FileDownloadName = folders[folders.Length - 1];
return result;
}
catch (Exception ex)
{
// log error
}
// how to handle if file is not found?
return new FileContentResult(new byte[] { }, "PDF");
}
そこBlobStorage
にあるクラスは、ブロブからストリームをダウンロードするヘルパー クラスです。
私の質問はコードのコメントに記載されています: ファイル/ストリームが見つからない場合、どのようにシナリオを処理すればよいですか? 現在、空の PDF ファイルを渡していますが、これは最善の方法ではないと感じています。