Store images/files into blob storage?
-
2012年7月6日 5:30
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.
すべての返信
-
2012年7月6日 6:39モデレータ
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
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
-
2012年7月6日 7:35
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);
} -
2012年7月6日 8:26モデレータ
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
- 回答としてマーク Arwind - MSFTModerator 2012年7月13日 3:59

