現在、Angularフロントエンドから.NET Web APIにファイルをアップロードしています。特定のサイズのファイルの角ファイルアップロードで 'Access-Control-Allow-Origin'ヘッダーエラーが発生しません。
uploadFile(file: File, customerId: number) {
var formData: FormData = new FormData();
formData.append('file', file, file.name);
var headers = new HttpHeaders().set('Accept', 'application/json');
var options = { headers: headers, reportProgress: true };
const req = new HttpRequest('POST', 'customers/' + customerId + '/fileupload', formData, options)
return this.http.request(req);
}
この投稿を受け取るWeb APIルート。
[HttpPost]
[Route("{customerId}/fileUpload")]
public IHttpActionResult UploadFiles(int customerId)
{
if (HttpContext.Current.Request.Files.Count > 0)
{
_fileService.UploadFile(customerId, HttpContext.Current.Request.Files[0]);
return Ok("Files Successfully Uploaded");
}
else
{
return Ok("0 Files Uploaded");
}
}
私は3000万バイト(〜30メガバイト)以下のファイルを投稿すると、すべてが期待通りに動作しますが、ファイルが大きい何らかの理由で、私はエラーを取得:
POST http://localhost:53319/customers/116/fileupload/Production 404 (Not Found)
Failed to load http://localhost:53319/customers/116/fileupload/Production: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 404.
私の場合、最大10Gbsのファイルをアップロードできる必要があります。私はそれを修正することができますどのように私は特定のサイズよりも大きなファイルのこのエラーを取得する誰も知っていますか?
私はすでにこれについていくつかの調査を行いましたが、Web.configファイルに以下を追加するだけですが、この問題は解決していません。
<system.web>
<httpRuntime maxRequestLength="2147483647" />
</system.web>
に関するいくつかのドキュメントです。ありがとうございました!この問題に遭遇する他の人にとって、 'maxAllowedContentLength'の型は' uint'で、最大値は4294967295です。つまり、私の場合、ファイルアップロードの最大値は〜4.29GBです。 –