如何使用MVC 4上传大文件? [英] How to upload large files using MVC 4?
本文介绍了如何使用MVC 4上传大文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有它的工作..但是我注意到,一旦我上传的文件变大(大约4000k),控制器将不会被调用。。
I had it working.. but I noticed once the files I was uploading get bigger (around 4000k) the controller would not be called..
所以我添加了在分块中解决了该问题..但是现在当我打开文件时,它充满了垃圾字符...
So I added in chunking which fixed that problem.. but now when I open the file its full of garbage characters...
那么用plupload上传大文件的正确方法是什么/ MVC 4?
So what is the correct way to upload large files with plupload/MVC 4 ?
这是我当前的代码
$(document).ready(function () {
var uploader = new plupload.Uploader({
runtimes: 'html5',
browse_button: 'pickfiles',
container: 'container',
// max_file_size: '20000mb',
url: '@Url.Action("Upload", "Home")',
chunk_size: '4mb',
//filters: [
// { title: "Excel files", extensions: "xls,xlsx" },
// { title: "Text files", extensions: "txt" }
//],
multiple_queues: true,
multipart: true,
multipart_params: { taskId: '' }
});
和控制器
[HttpPost]
public ActionResult Upload(int? chunk, string name, string taskId)
{
string filePath = "";
var fileUpload = Request.Files[0];
var uploadPath = Server.MapPath("~/App_Data/Uploads");
chunk = chunk ?? 0;
string uploadedFilePath = Path.Combine(uploadPath, name);
var fileName = Path.GetFileName(uploadedFilePath);
try
{
using (var fs = new FileStream(filePath, 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);
}
//Log to DB for future processing
InstanceExpert.AddProcessStart(filePath, Int32.Parse(taskId));
}
推荐答案
在web.config中,您需要这些(大约2GB):
In web.config you need these (2GB all around):
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
...
</system.web>
这篇关于如何使用MVC 4上传大文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文