I have an Azure Blob Storage where I want to upload some files.
Index.cshtml
@using (Html.BeginForm("File_post", "MyController", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="editor-label">
<p>
<input type="file" name="file" />
</p>
<input type="submit" value="Upload" />
</div>
}
MyController.cs
public ActionResult File_post(HttpPostedFileBase file)
{
CloudBlobContainer blobContainer = Initialize(); // This Initialize my blobContainer
CloudBlockBlob blob;
blob = blobContainer.GetBlockBlobReference("myfile");
blob.UploadFromStream(file.InputStream);
Return("Index");
}
I tested with a 3.5Mo file, it works even with a 20Mo file. Now I try with a 33Mo and firefox gives me the basic error : The connection was reset...
Edit: When I put
public ActionResult File_post(HttpPostedFileBase file)
{
Return("Index");
}
It gives me the same error, so I think it's not caused by my c# code.
Any idea ? Thanks a lot !
If no exception throws from your code, it means the blob has been uploaded successfully. Otherwise, a exception will be thrown. You can also confirm it using any web debugging proxy tool(ex. Fiddler) to capture the response message from storage server.
You'll need to modify your web.config to allow large file uploads in ASP.NET and IIS (the following example will allow a 50MB file upload):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime maxRequestLength="51200" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="51200000" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With