我有以下型號:上傳文件到網絡API
public class FileModel
{
public byte[] FileData{get;set;}
public string FileName {get;set;}
}
我已經編寫這我的Web應用程序消耗私有的Web API服務。 當用戶上傳文件時,我將這些文件轉換爲字節數組,並從C#代碼(不是從HTML頁面發送List<FileModel>
到我的Web API,因爲我的Web API從我的網站是私人的),這將保存我的文件和返回結果。
的Web API方法:
[HttpPost]
public UploadFiles(List<FileModel> files)
{
// Do work
}
上面的代碼休息,如果我上傳許多大型文件 - 代碼的失敗,因爲它們超出了最大長度序列化序列化大文件FileModel
秒。
如何解決此問題?有沒有其他方法可以將文件上傳到Web API而不會將其暴露給用戶?
的可能的複製[如何上傳與進度ASP.NET MVC4網絡API一個大文件(https://stackoverflow.com/questions/15506648/how-to-upload-a-large-file -with-asp-net-mvc4-web-api-with-progressbar) – Liam
使用塊字節方法異步上傳。 https://stackoverflow.com/questions/583970/need-loop-to-copy-chunks-from-byte-array –
@NikhilKS我不想做多個網絡API調用。 –