I am trying to figure out how to upload files from an asp:FileUpload server tag. I know how to create the straoge account, blobclient, and container, I just know how to save the file from the Upload tag into the container. I have gone some google searching
but can not find anything that talk about doing it in Web Froms using a FileUpload tag. Can anyone please help?
Edit. Sorry, this post had nothing to do with your question. I hit the back button one too many times when writing out an answer to another post. Though I think I can help you. I'll reply to your last post so you get notified.
If by secure you mean only allow authenticated users to view the video then follow these steps. First, you will want to store the video in Azure BLOB storage and turn off public access. Next you will have a web page that has some kind of user authentication
in place. There are a number of different methods for authentication, but one simple option is to use the built-in ASP.NET SQL Membership Provider. You can even set this up to use Windows Azure SQL Database. If you do go down that route there are a few extra
steps you need to take. See below link. In summary, you will make it so that only your website can access the videos in BLOB storage, and only authenticated users can view the content of your website.
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");
// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
blockBlob.UploadFromStream(fileStream);
}
You will simply have to replace the last part to read from your fileuipload object. So it will look like this
using (YourFileUpload.PostedFile.InputStream)
{
blockBlob.UploadFromStream((FileStream)YourFileUpload.PostedFile.InputStream);
}
Just make sure you replace the above bolded object with whatever name you gave your FileUpload control.
// Retrieve storage account from connection string. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the blob client. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve reference to a previously created container. CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); // Retrieve reference to a blob named "myblob". CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob"); // Create or overwrite the "myblob" blob with contents from a local file. using (var fileStream = System.IO.File.OpenRead(@"path\myfile")) { blockBlob.UploadFromStream(fileStream); }
You will simply have to replace the last part to read from your fileuipload object. So it will look like this
Just make sure you replace the above bolded object with whatever name you gave your FileUpload control.
Thatnk you I had acutaly been working based off the link you gave but was not sure hwo to convert the last line to use the fileupload. I will give this a shot this weekend.
Eagle_f90
Member
465 Points
531 Posts
Upload files to Azure storage from ASP.Net 4.5 Web Forms?
Feb 03, 2013 10:53 PM|LINK
I am trying to figure out how to upload files from an asp:FileUpload server tag. I know how to create the straoge account, blobclient, and container, I just know how to save the file from the Upload tag into the container. I have gone some google searching but can not find anything that talk about doing it in Web Froms using a FileUpload tag. Can anyone please help?
jamesqua
Star
8305 Points
1430 Posts
Re: Upload files to Azure storage from ASP.Net 4.5 Web Forms?
Feb 08, 2013 03:16 PM|LINK
Edit. Sorry, this post had nothing to do with your question. I hit the back button one too many times when writing out an answer to another post. Though I think I can help you. I'll reply to your last post so you get notified.
Eagle_f90
Member
465 Points
531 Posts
Re: Upload files to Azure storage from ASP.Net 4.5 Web Forms?
Feb 08, 2013 04:56 PM|LINK
I am sorry I do not see how this relates to saving files to the blob from a asp:Fileupload control
jamesqua
Star
8305 Points
1430 Posts
Re: Upload files to Azure storage from ASP.Net 4.5 Web Forms?
Feb 08, 2013 05:35 PM|LINK
Alright, first of all you'll need code to write to the BLOB. Here is short tutorial for that. http://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/
The meat of the code is here:
// Retrieve storage account from connection string. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the blob client. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve reference to a previously created container. CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); // Retrieve reference to a blob named "myblob". CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob"); // Create or overwrite the "myblob" blob with contents from a local file. using (var fileStream = System.IO.File.OpenRead(@"path\myfile")) { blockBlob.UploadFromStream(fileStream); }You will simply have to replace the last part to read from your fileuipload object. So it will look like this
using (YourFileUpload.PostedFile.InputStream) { blockBlob.UploadFromStream((FileStream)YourFileUpload.PostedFile.InputStream); }Just make sure you replace the above bolded object with whatever name you gave your FileUpload control.
Eagle_f90
Member
465 Points
531 Posts
Re: Upload files to Azure storage from ASP.Net 4.5 Web Forms?
Feb 08, 2013 05:47 PM|LINK
Thatnk you I had acutaly been working based off the link you gave but was not sure hwo to convert the last line to use the fileupload. I will give this a shot this weekend.