我有它的工作..但我注意到,一旦我上传的文件越来越大(大约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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。