gpt4 book ai didi

asp.net-mvc - 如何上传多个大文件 ASP.Net MVC

转载 作者:行者123 更新时间:2023-12-04 20:03:16 25 4
gpt4 key购买 nike

这里我想指出我从这里找到的代码 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>

关于asp.net-mvc - 如何上传多个大文件 ASP.Net MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31026722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com