none
Upload images to Azure storage

    Question

  • Hi All,

    Have written code to upload images to Azure storages.

    I am able to upload images to azure from my local system, but when i upload the application to Azure website and when i try to upload images from Azure website i am getting error as below

    <Error>
    <Code>BlobNotFound</Code>
    <Message>
    The specified blob does not exist. RequestId:84a35380-0001-0019-0c8d-884bb7000000 Time:2015-03-11T14:11:35.4568293Z
    </Message>

    </Error>

    404 The specified blob does not exist.

    Below is the code i am using to upload images to azure storage.

    StorageCredentials cred = new StorageCredentials(Sasquerystring);
    var imageUri = new Uri(Imageuri);

    // Instantiate a Blob store container based on the info in the returned item.
    CloudBlobContainer container =  new CloudBlobContainer(new Uri(string.Format("https://{0}/{1}", imageUri.Host, Containername)), cred);

    // Upload the new image as a BLOB from the stream.
    CloudBlockBlob blobFromSASCredential = container.GetBlockBlobReference(Resourcename);

    Int32 length = fileStream.Length > Int32.MaxValue ? Int32.MaxValue : Convert.ToInt32(fileStream.Length);
    Byte[] buffer = new Byte[length];
    fileStream.Read(buffer, 0, length);

    // await blobFromSASCredential.UploadFromStreamAsync(fileStream);
    await blobFromSASCredential.UploadFromByteArrayAsync(buffer, 0, buffer.Length);

    buffer = null;

    Thanks,

    Sai.

    Wednesday, March 11, 2015 2:16 PM

Answers

  • Hello Sai,

    I tried the exact same code and it worked both from my local machine and azure websites.  Can you check the following:

    1. How did you provide path to the image? In order to provide the path to the file, I used
    string pathToFiles = HttpContext.Current.Server.MapPath("/image/CSC_0010.JPG");

    2. The error message indicates that the blob does not exists. Make sure that the blob you are trying to upload the file to does exists. Sample:  https://test.blob.core.windows.net/test1/testblob

    Thanks
    Farida





    Monday, March 16, 2015 9:54 PM

All replies

  • Hi Sai,

    You could refer the following link for details on using Azure Blob Storage with Azure Websites:

    http://www.codeproject.com/Articles/490178/How-to-Use-Azure-Blob-Storage-with-Azure-Web-Sites

    Regards,
    Malar.

    Disclaimer: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Wednesday, March 11, 2015 2:54 PM
  • Hi Malar,

    Actually the problem is, i am able to upload the image from my local machine to azure storage

    but the problem is when i move the application to azure website and then try to upload form azure website , the images are not getting uploaded.

    Thanks,

    Sai.

    Wednesday, March 11, 2015 3:03 PM
  • Hi Sai,

    Would you be able to provide us the Fiddler traces?
    Also please do Turn on storage analytics so we can try and check the Storage logs.

    Regards,
    Malar.

    Monday, March 16, 2015 4:26 PM
  • Hello Sai,

    I tried the exact same code and it worked both from my local machine and azure websites.  Can you check the following:

    1. How did you provide path to the image? In order to provide the path to the file, I used
    string pathToFiles = HttpContext.Current.Server.MapPath("/image/CSC_0010.JPG");

    2. The error message indicates that the blob does not exists. Make sure that the blob you are trying to upload the file to does exists. Sample:  https://test.blob.core.windows.net/test1/testblob

    Thanks
    Farida





    Monday, March 16, 2015 9:54 PM