Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPA cannot upload files, got no CORS header error #16

Closed
rivernews opened this issue Sep 8, 2019 · 3 comments
Closed

SPA cannot upload files, got no CORS header error #16

rivernews opened this issue Sep 8, 2019 · 3 comments

Comments

@rivernews
Copy link
Owner

As image:

Screen Shot 2019-09-07 at 7 01 49 PM

@rivernews
Copy link
Owner Author

Debug

1. Switch Django to use runserver on K8 to view log. Check Django stream log.

Result: no incoming request log.

2. Check stream log of nginx controller.

Result:

2019/09/08 07:00:37 [error] 210#210: *1164519 client intended to send too large body: 1127005 bytes, client: 73.93.154.248, server: api.shaungc.com, request: "POST /api/uploads/ HTTP/2.0", host: "api.shaungc.com", referrer: "https://shaungc.com/blog/109"
73.93.154.248 - [73.93.154.248] - - [08/Sep/2019:07:00:37 +0000] "POST /api/uploads/ HTTP/2.0" 413 591 "https://shaungc.com/blog/109" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" 95 0.000 [-] [] - - - - 39918f6d3e9b043f3abd9dcb09703cdb

So we checked the related issue, also checked that our uploaded file size is 1.1M.

This made us want to further inspect if there's any file size limit in nginx.conf, so done . ./my-kubectl.sh exec -it -n kube-system nginx-ingress-controller-controller-2jnf9 cat /etc/nginx/nginx.conf > nginx.conf and bingo:

client_max_body_size                    1m;

So it never reaches Django, so any config in Django didn't take effect.

@rivernews
Copy link
Owner Author

rivernews commented Sep 8, 2019

Action

We actually don't want too large image on the website, so the limit is of good intention.

  • Let SPA angular stop user when uploading too large file.
  • Let nginx remain the file size limit 1MB, but make it explicit - either explicitly set it in configmap or annotation.
  • Django don't need to do anything yet here, just have to clean up code after test above succeed.

rivernews added a commit to rivernews/iriversland2-spa that referenced this issue Sep 8, 2019
rivernews added a commit that referenced this issue Sep 8, 2019
@rivernews
Copy link
Owner Author

We got a wrong file url that points to static file bucket. But when we look at the media bucket, the file is created.

This is because of the implementation of class S3Boto3Storage. After manually specifying custom_domain, it's now working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant