Search code examples
c#asp.net-mvc-3azurecloudblob

BlobType of the blob reference doesn't match BlobType of the blob?


i have store file in Blob container as below code i.e:

  CloudBlob blob = container.GetBlobReference("Images/page11/Orange box.png");
  blob.UploadFromStream(mnm);
  blob.Metadata["FileName"] = "Orange box.png";
  blob.SetMetadata();

i have successfully store in the container like as "Images/page11/Orange box.png" but when i fetch attribute i got error BlobType of the blob reference doesn't match BlobType of the blob using this code.

            blob.FetchAttributes();
            return true;

Is this right way to get Blob from container?


Solution

  • I don't know how you are getting that error exactly but it looks as though it is to do with the BlobType. Not sure if you already know but there are two types of blobs, block and page. For images you are usually better off with using Block blobs. So change the first line to container.GetBlockBlobReference("etc...");

    Anyway, to answer your question to get the blob from container you can do blob.DownloadToFile or DownloadToByteArray or DownloadAsText. Which ever is most relevant for you.

    Not sure what you are trying to do exactly but since it is an image you can just do a webrequest to that location if that is more convenient for you e.g. <img src="http://myapp.blob.core.windows.net/myaccount/images/page11/orange box.png" /> or find it direct in a browser.

    It looks like you are trying to find attributes though in that bit of code? If so you can simply do blob.Attributes.MetaData["FileName"]