2017-11-02 2 views
0

現在、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> 

答えて

1

この種のweb.configまたは少なくともrequestLimitsの部分を試してください。これは.Net Coreプロジェクトのものなので、構文が異なる可能性があります。ここで

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.webServer> 
    <security> 
     <requestFiltering> 
      <requestLimits maxAllowedContentLength="524288000"/> 
     </requestFiltering> 
    </security> 
    <handlers> 
     <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/> 
    </handlers> 
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/> 
    </system.webServer> 
</configuration> 

https://github.com/JanneHarju/MultiSourcePlayList/blob/cbbe3460d107cd07d01ee80e0693f905a295f392/web.config#L11

は、私は必要なすべては ` `セクションだったこと https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/requestlimits/

The default value is 30000000, which is approximately 28.6MB.

+0

に関するいくつかのドキュメントです。ありがとうございました!この問題に遭遇する他の人にとって、 'maxAllowedContentLength'の型は' uint'で、最大値は4294967295です。つまり、私の場合、ファイルアップロードの最大値は〜4.29GBです。 –

関連する問題