i have written below code to upload a file in windows azure. user need to enter the path of the video file on the local drive like D:\video\1.mp4 and name of the video. i push both the information in the queue. on click of upload button it will read the queue and fetch the path and upload the video content. Below code work fine on local machine when i upload the same code on azure webrole its failing to read the path
string[] x = retrievedMessage.AsString.Split(','); queue.DeleteMessage(retrievedMessage);
using (var fileStream = System.IO.File.OpenRead(x[1]))
{
blockBlob.UploadFromStream(fileStream);
}
I guess there is one web role and one work role (at least) in your system. User select his/her file and provide name in the website, and then your web role generate a message and push into the queue. Then your worker retrieve the message and tried to read the file and save in blob in background.
If my assumption were correct, you should met the error you mentioned, since the worker role cannot read user's local file from the message { "path": "D:\1.mp4", "name": "1.mp4" }
.
One solution is to upload the file from your web role into blob directly. But this might cause problem if file was very large.
Alternatively you can use JavaScript and HTML5 to upload file in parallel in background in browser (user must not refresh or leave your page). Basically you can generate a SAS of you blob container and render into your page, then read the file in blocks through JavaScript and upload them directly to blob. And finally send request to combine these blocks into blob.
Here is one of my blog post might helps http://blog.shaunxu.me/archive/2013/07/01/upload-file-to-windows-azure-blob-in-chunks-through-asp.net.aspx