# Issue with CORS and Javascript client? Wrong! client\_max\_body\_size was not set properly when trying to upload via custom API Endpoint

**URL:** https://meta.discourse.org/t/issue-with-cors-and-javascript-client-wrong-client-max-body-size-was-not-set-properly-when-trying-to-upload-via-custom-api-endpoint/164189
**Category:** General
**Created:** [September 16, 2020, 11:30am UTC](https://meta.discourse.org/t/issue-with-cors-and-javascript-client-wrong-client-max-body-size-was-not-set-properly-when-trying-to-upload-via-custom-api-endpoint/164189 "2020-09-16T11:30:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Stefan\_Brighiu\_M](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stefan_brighiu_m/32/174499_2.png) [@Stefan\_Brighiu\_M](https://meta.discourse.org/u/Stefan_Brighiu_M)
#### Post date: [September 16, 2020, 11:30am UTC](https://meta.discourse.org/t/issue-with-cors-and-javascript-client-wrong-client-max-body-size-was-not-set-properly-when-trying-to-upload-via-custom-api-endpoint/164189/1 "2020-09-16T11:30:11Z")

</div>

I’m trying to upload files via a custom endpoint and using an user api from my website.

I can log in only with an admin user.  
I can literally do anything else, other than uploading files.

```plaintext
> [Error] Origin https://my.domain is not allowed by Access-Control-Allow-Origin.
> [Error] Fetch API cannot load https://my.domain/m/upload.json due to access control checks.
> [Error] Failed to load resource: Origin https://my.domain is not allowed by Access-Control-Allow-Origin. (upload.json, line 0)
> [Log] API-CALL-ERROR – "/m/upload.json" – TypeError: Origin https://my.domain is not allowed by Access-Control-Allow-Origin. (app.8eb0470a.chunk.js, line 1)
> TypeError: Origin https://my.domain is not allowed by Access-Control-Allow-Origin.

```

I’ve added `https://my.domain` and `http://localhost:19006` (for testing) in Settings CORS and I added DISCOURSE\_ENABLE\_CORS true to app.yml.

I also tried to add `https://my.domain` in DISCOURSE\_CORS\_ORIGIN in app.yml but also that did not work.

What am I missing?

---

<div class="post-metadata">

### Author: ![Stefan\_Brighiu\_M](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stefan_brighiu_m/32/174499_2.png) [@Stefan\_Brighiu\_M](https://meta.discourse.org/u/Stefan_Brighiu_M)
#### Post date: [September 16, 2020, 11:44am UTC](https://meta.discourse.org/t/issue-with-cors-and-javascript-client-wrong-client-max-body-size-was-not-set-properly-when-trying-to-upload-via-custom-api-endpoint/164189/2 "2020-09-16T11:44:38Z")

</div>

The only thing i see in /shared/log/rails/production.log is ![Screen Shot 2020-09-16 at 14.44.02](https://global.discourse-cdn.com/meta/original/3X/2/e/2e3bd00ebfecc3260e6d452b72d92b527270b793.png)

---

<div class="post-metadata">

### Author: ![Stefan\_Brighiu\_M](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stefan_brighiu_m/32/174499_2.png) [@Stefan\_Brighiu\_M](https://meta.discourse.org/u/Stefan_Brighiu_M)
#### Post date: [September 17, 2020, 9:14am UTC](https://meta.discourse.org/t/issue-with-cors-and-javascript-client-wrong-client-max-body-size-was-not-set-properly-when-trying-to-upload-via-custom-api-endpoint/164189/3 "2020-09-17T09:14:12Z")

</div>

TL;DR  
Check all nginx or servers implicated. In my case, 3 to count: website, discourse docker, and inside discourse docker. client\_max\_body\_size should be set to the limit you want to have when uploading.

I chose ‘client\_max\_body\_size 999m’ just because I wanted to limit it from discourse settings only. You can add that line inside the http or server tags inside nginx.conf. I prefer to add it on the last line, just to be safe 🙂

Longer version:  
After an entire day of digging and downloading firefox… totally recommend it for web dev. I found out that the reason I couldnt upload was because of the limit set by the nginx inside the docker container of discourse (some might say yeah.. but that is dynamically set when launcher is rebuilt… - i like to be sure 🙂 ). Then there was the fact that our own nginx that hosts the docker image didnt have a limit set, that defaulted to ‘client\_max\_body\_size 1MiB’, which is not good enough :). After changing that too, I had to go on the frontend nginx and change that too. 3 changes, 6 hours of dabbling with CORS pre-flight request management in nginx and a bit of stress, it now works.
