我有一个控制器操作,它根据容器引用名称(即 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
类是我的帮助类,用于从 blob 下载流。
我的问题在代码注释中说明:找不到文件/流时我应该如何处理这种情况?目前,我正在传递一个空的 PDF 文件,我觉得这不是最好的方法。