Why am I having CORS error on uploading larger files?

Viewed 2607

I am using C# on .NET Core for the back-end API and Angular 6 for the front-end. When I upload a file to test on my localhost, I can upload any size file without error, but when on the production, it limits me to upload to 64KB. If the file I try to upload is larger than 64KB, it throws an error

No Access-Control-Allow-Origin header is present on the requested resource How can this be solved?

1 Answers

To allow larger file size, you need to update your Web.config file for your API.

Under your <system.webServer> tag, please add the following and define the size

 <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483648" /> <!--2GB-->
     </requestFiltering>
    </security>  

You can set any size but make sure the timeout is long enough to process the request if it's a huge file otherwise the API will throw a Timeout error

the timeout can be set in web.config also as following

<httpRuntime targetFramework="4.7.2" executionTimeout="9999" maxRequestLength="2000000" /> <!--approx 2GB-->

For more information please see the following

https://forums.asp.net/post/6084972.aspx

https://www.strathweb.com/2012/09/dealing-with-large-files-in-asp-net-web-api/

Hope this helps

Related