6
votes

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 !

1

1 Answers

7
votes

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>