如何上传多个大文件ASP.Net MVC

How to upload multiple large file ASP.Net MVC

这里我想指出我从这里找到的代码 Using plupload with MVC3。其目的是上传单个文件,但我的要求有点不同,比如我需要上传几个大文件,比如 3 个文件,每个文件大小可能为 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
        });
    }
});

只是想知道任何人都可以告诉我我还需要在上面的服务器端和客户端代码中添加什么,使我能够上传多个大文件。谢谢

您可能需要在 web.config 文件中添加一个条目以允许较大的文件大小 (2097152KB = 2GB)。您可以相应调整的超时秒数:

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

您还可以将请求限制(以字节为单位)设置为 2GB,

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