I have a controller action that loads a file from azure blob based on the name of the container reference (i.e. the full path name of the file in the blob). The code looks something like this:
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"); }
In the BlobStorage class, BlobStorage is my helper class for loading a stream from a blob.
My question is indicated in the code comment: How do I handle a script when a file / stream is not found? I am currently transferring an empty PDF file which, in my opinion, is not the best way to do this.
c # asp.net-mvc-2 azure-storage-blobs filecontentresult
Alex R.
source share