ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Protected Attributes | List of all members
ImageResizer.Plugins.AzureReader2.AzureFile Class Reference
Inheritance diagram for ImageResizer.Plugins.AzureReader2.AzureFile:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Plugins.AzureReader2.AzureFile:
Collaboration graph
[legend]

Public Member Functions

 AzureFile (string blobName, AzureVirtualPathProvider parentProvider)
 
override System.IO.Stream Open ()
 Attempts to download the blob into a MemoryStream instance and return it. Throws a FileNotFoundException if the blob doesn't exist. More...
 

Protected Attributes

readonly AzureVirtualPathProvider parent
 

Additional Inherited Members

- Properties inherited from ImageResizer.Plugins.IVirtualFile
string VirtualPath [get]
 The virtual path of the file (relative to the domain, like /app/folder/file.ext) More...
 

Detailed Description

Definition at line 11 of file AzureFile.cs.

Member Function Documentation

override System.IO.Stream ImageResizer.Plugins.AzureReader2.AzureFile.Open ( )
inline

Attempts to download the blob into a MemoryStream instance and return it. Throws a FileNotFoundException if the blob doesn't exist.

Returns

Implements ImageResizer.Plugins.IVirtualFile.

Definition at line 22 of file AzureFile.cs.

22  {
23  // Prefix already stripped from virtual path
24 
25  // Get a reference to the blob
26  // mb: 12/8/2012 - the path needs to be a uri now, so combining blobclient baseuri with the virtualpath
27  Uri blobUri = new Uri(string.Format("{0}/{1}", parent.CloudBlobClient.BaseUri.OriginalString.TrimEnd('/', '\\'), VirtualPath));
28  ICloudBlob cloudBlob = parent.CloudBlobClient.GetBlobReferenceFromServer(blobUri);
29 
30  MemoryStream ms = new MemoryStream(4096); // 4kb is a good starting point.
31 
32  // Synchronously download
33  try {
34  cloudBlob.DownloadToStream(ms);
35  }
36  catch (StorageException e) {
37  // mb: 12/8/2012 - not sure of the correctness of these following lines
38  // in other areas we just check e.RequestInformation.HttpStatusCode == 404 for a Not Found error
39  // don't know what the errorcodes that will be returned
40  if (e.RequestInformation.ExtendedErrorInformation.ErrorCode == "BlobNotFound") {
41  throw new FileNotFoundException("Azure blob file not found", e);
42  }
43  else if (e.RequestInformation.ExtendedErrorInformation.ErrorCode == "ContainerNotFound")
44  {
45  throw new FileNotFoundException("Azure blob container not found", e);
46  }
47  else {
48  throw;
49  }
50  }
51 
52  ms.Seek(0, SeekOrigin.Begin); // Reset to beginning
53  return ms;
54  }
string VirtualPath
The virtual path of the file (relative to the domain, like /app/folder/file.ext)
Definition: IVirtualFile.cs:14

The documentation for this class was generated from the following file: