How to upload multiple large ASP.Net MVC files

here i want to point the code i found here Using plupload with MVC3 . whose intent is to upload a single file, but my requirement is slightly different since I need to upload multiple large files, say 3 files, and each file size can be 2GB.

[HttpPost]
public ActionResult Upload(int? chunk, string name)
{
    var fileUpload = Request.Files[0];
    var uploadPath = Server.MapPath("~/App_Data");
    chunk = chunk ?? 0;
    using (var fs = new FileStream(Path.Combine(uploadPath, name), chunk == 0 ? FileMode.Create : FileMode.Append))
    {
        var buffer = new byte[fileUpload.InputStream.Length];
        fileUpload.InputStream.Read(buffer, 0, buffer.Length);
        fs.Write(buffer, 0, buffer.Length);
    }
    return Json(new { message = "chunk uploaded", name = name });
}

$('#uploader').pluploadQueue({
    runtimes: 'html5,flash',
    url: '@Url.Action("Upload")',
    max_file_size: '5mb',
    chunk_size: '1mb',
    unique_names: true,
    multiple_queues: false,
    preinit: function (uploader) {
        uploader.bind('FileUploaded', function (up, file, data) {
            // here file will contain interesting properties like 
            // id, loaded, name, percent, size, status, target_name, ...
            // data.response will contain the server response
        });
    }
});

      

just wondering if someone can tell me what else I need to add to the server-side and client-side code that allows me to upload multiple large files. thank

+3


source to share


1 answer


You may need to add an entry to your file web.config

to allow the large file size (2097152KB = 2GB). The timeout in seconds can be adjusted accordingly:

<system.web>
    <httpRuntime maxRequestLength="2097152" executionTimeout="3600" />
</system.web>

      



also you can set the request limit (which is in bytes) equal to 2 GB,

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="2147483648"/>
        </requestFiltering>
    </security>
</system.webServer>

      

+1


source







All Articles