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

时间:2015-06-24 12:34:32

标签: asp.net-mvc plupload

这里我想指出一个我在这里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
        });
    }
});

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

1 个答案:

答案 0 :(得分:1)

您可能需要在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>