CORS error upload file ~4mb
Asked Answered
R

4

3

I'm building an app where angular front-end is on s3 as static website and Sails (0.10.3) API inside dokku with Node 0.11.13 and SSL on EC2. If file is larger than about 4mb I got error "No 'Access-Control-Allow-Origin' header is present on the requested resource." OPTIONS request is hitting my API and I can catch it in customMiddleware but the POST with data is not reaching that far. On front-end side I'm using angularjs-file-upload. If I turn off SSL then it works without any problems but I would prefer to keep it on.

Rosaline answered 29/8, 2014 at 12:47 Comment(2)
Are you sure it allows requests larger than 4 MiB ?Minnow
Yes, I'm totally sure. I turned off SSL and then it works without any problems.Vulnerable
R
1

I went up the chain app itself -> dokku -> SSL and the problem was even higher, in nginx.

nginx.conf required one line more: proxy_read_timeout 1200s;

Rosaline answered 29/8, 2014 at 21:36 Comment(0)
P
3

One more thing you can try, if it's Nginx that's causing issues. Look into your error log file. Generally its /var/log/nginx/error.log
In that if you see this line *133774 client intended to send too large body: 3141911 bytes

It means the issue is of the size and you might wanna fix it.

The way you do it is in your nginx.conf in the HTTP context paste this anywhere.

client_max_body_size 50M;

This will allow you to increase your body size to 50M.
Hence fixing the issue

Pirtle answered 4/10, 2020 at 7:46 Comment(0)
R
1

I went up the chain app itself -> dokku -> SSL and the problem was even higher, in nginx.

nginx.conf required one line more: proxy_read_timeout 1200s;

Rosaline answered 29/8, 2014 at 21:36 Comment(0)
C
1

I had a similar solution and I solved it with the help of this. It's because of the client_max_body_size configuration variable that Nginx has.

Consortium answered 7/9, 2021 at 14:31 Comment(0)
A
1

1.Go to nginx configuration setting file:

sudo nano /etc/nginx/nginx.conf

2.Change in nginx.conf file:

http {
clientmaxbody_size 100m;
}

3.Restart Your Nginx:

sudo service nginx restart 
or 
service nginx reload

for my MEAN Stack (node & Expreess js) application it worked. Hoping for your case too !

Another EXPRESS code if 1,2 & 3 point won't work for you
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors());

Below link for reference full detail explanation: https://www.digitalocean.com/community/questions/how-to-edit-nginx-setting-for-big-file-upload

Adversary answered 3/12, 2021 at 14:25 Comment(1)
In the 2nd step I got an error and fixed it by changing it like that client_max_body_size 100m;Arcanum

© 2022 - 2024 — McMap. All rights reserved.