我有它的工作..但我注意到,一旦我上传的文件越来越大(大约4000k)控制器不会被调用..
所以我添加在chunking哪个修复了这个问题..但现在当我打开的文件,其完整的垃圾字符…
那么什么是正确的方式上传大文件与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,buffer.Length); fs.Write(buffer,buffer.Length); } //Log to DB for future processing InstanceExpert.AddProcessStart(filePath,Int32.Parse(taskId)); }
解决方法
在web.config你需要这些(2GB四周):
<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>