none
Store images/files into blob storage? RRS feed

  • Question

  • Hi,

    I would like to store my application's dynamic(user's uploaded dynamically) images into windows azure blob storage instead of my local application folder.

    I need complete code to implement it. Please help me guys.

    Waiting for your kind reply.

    Friday, July 6, 2012 5:30 AM

Answers

  • Hi,

    It seems your put a incorrect file path when you trying to upload it, Can you make sure the "Penguins.jpg" is under the "'c:\windows\system32\inetsrv\"? And i suggest you use PostedFile.PostedFile.InputStream instead of File.OpenRead method (get the image stream directly).

    Another thing is Blob.UploadFile method is also available, you can use the Server.MapPath to get the image url, code snippets like:

    string name = "File/Microsoft.jpg";                   
    CloudBlob blob = container.GetBlobReference(name);
    blob.UploadFile(Server.MapPath(name));

    Hope this helps.

    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    Friday, July 6, 2012 8:26 AM
    Moderator

All replies

  • Hi,

    If you need complete code for archieveing your goals, i suggest you post your idea as sample request to Microsoft All-In-One Code Framework, i believe they will glad to see it and give a quick response:

    http://1code.codeplex.com/workitem/list/basic

    Hope this helps.


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    Friday, July 6, 2012 6:39 AM
    Moderator
  • ok thanks Arwind.

    I tried this. but i am getting error in the following blocked lines like 'Could not find file 'c:\windows\system32\inetsrv\Penguins.jpg'. How can i resolve this.

    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
                            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                            CloudBlobContainer container = blobClient.GetContainerReference("ia-container");
                            container.CreateIfNotExist();
                            container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
                            CloudBlob blob = container.GetBlobReference("article-blob");
    using (var fileStream = System.IO.File.OpenRead(FileUpload1.PostedFile.FileName))
                            {
                                blob.UploadFromStream(fileStream);
                            }

    Friday, July 6, 2012 7:35 AM
  • Hi,

    It seems your put a incorrect file path when you trying to upload it, Can you make sure the "Penguins.jpg" is under the "'c:\windows\system32\inetsrv\"? And i suggest you use PostedFile.PostedFile.InputStream instead of File.OpenRead method (get the image stream directly).

    Another thing is Blob.UploadFile method is also available, you can use the Server.MapPath to get the image url, code snippets like:

    string name = "File/Microsoft.jpg";                   
    CloudBlob blob = container.GetBlobReference(name);
    blob.UploadFile(Server.MapPath(name));

    Hope this helps.

    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    Friday, July 6, 2012 8:26 AM
    Moderator