I have created a WCF REst web service with C# where i'm trying to upload a blob in the local Azure Storage Account. I created a FileUpload control and a button so that i can choose the file to be uploaded, but i am unable to upload.. Here's my code:
public class Service : IService
{
[WebInvoke(Method = "POST", UriTemplate = "Upload", ResponseFormat =
WebMessageFormat.Json)]
public void Upload(string path)
{
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnection"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
//Get the reference of the container in which the blobs are stored
CloudBlobContainer container = blobClient.GetContainerReference("upload");
//Set the name of the uploaded document to a unique name
string docName = "Document_" + Guid.NewGuid().ToString() + ".txt";
//Get the blob reference and set its metadata properties
CloudBlockBlob blockBlob = container.GetBlockBlobReference(docName);
using (var fileStream = System.IO.File.OpenRead(path))
{
blockBlob.UploadFromStream(fileStream);
}
}
Then in my web form, i have the following design:
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="uplFileUpload" runat="server" />
<br /><br />
</div>
<asp:Button ID="btnUpload" runat="server" Text="Upload"
onclick="btnUpload_Click" />
<asp:Button ID="btnDisplayBlobs" runat="server" Text="Display Blobs"
onclick="btnDisplayBlobs_Click" />
<br />
<p>
<asp:Label ID="lblURIs" runat="server" Text=""></asp:Label>
</p>
</form>
And finally here's the code for when i click my button:
public partial class WebClient : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUpload_Click(object sender, EventArgs e)
{
Service blob = new Service();
if (uplFileUpload.HasFile)
{
blob.Upload(uplFileUpload.PostedFile.FileName);
}
}
This is the error i get: