netcore文件上傳的坑


前端用Form表單包裹文件input,上傳時傳參new FormData($("#submitVideo")[0])

但是!!!后台Request.Form.Files[i]取不到文件,Form里面就已經拋了異常,一般會出現錯誤:

  System.IO.InvalidDataException: Multipart body length limit 16384 exceeded

core默認只能傳輸10+k的文件?應該不是的,不過我沒找着原因。

解決方法:

  1. 在startup.cs的ConfigureServices方法加入:

    services.Configure<FormOptions>(x =>

   {   x.ValueLengthLimit = int.MaxValue;   x.MultipartBodyLengthLimit = int.MaxValue; // In case of multipart   });  
2. 在被調用方法添加入參

  [HttpPost]
  public ActionResult UploadOther(IFormCollection files)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM