【发布时间】:2017-03-01 20:56:33
【问题描述】:
我正在使用 ngResource 和 Angular 将文件上传到 ASP.NET Web 服务。
在我尝试超过一定大小(约 50MB)的文件之前,一切正常。在某个大小之后,FromBody 参数没有被绑定,我得到了一个null DocumentDTO 对象引用。
有什么解决办法吗?
在我的 web.config 中,我有以下设置:
maxAllowedContentLength="500000000"
和
maxRequestLength="200000"
在我的控制器中,我有:
[HttpPost, Route("{id:Guid}")]
public async Task<IHttpActionResult> Insert([FromUri]Guid id, [FromBody]DocumentDTO documentDTO)
{
//...
我的DocumentDTO 是:
public class DocumentDTO
{
[Required]
public Guid Id { get; set; }
[DisplayFormat(ConvertEmptyStringToNull = false)]
[MaxLength(250)]
public string FileName { get; set; }
[Required]
public string Content { get; set; }
[MaxLength(250)]
public string ContentType { get; set; }
}
在我的 Angular 控制器中,我有以下代码:
vm.document.$save(
data => {
notifications.success("The document has been uploaded to the repository.", "Upload Succeeded");
},
err => {
errorService.handleApiError(err, "document", "upload");
})
.finally(() => vm.loading = false);
通过在FileReader 上调用readAsArrayBuffer 来设置vm.document.content 值。
就像我说的:这一切在一定的文件大小下都可以正常工作。是FileReader有限制没有正确设置文件内容,还是WebApi对模型绑定有限制?
【问题讨论】:
-
尝试使用 Postman 或其他 HTTP 客户端测试文件上传到服务器。
标签: c# asp.net asp.net-web-api