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

Cannot POST files using CORS_ALLOW_CREDENTIALS = True and CORS_ORIGIN_ALLOW_ALL = True #601

Closed
Myzel394 opened this issue Dec 18, 2020 · 6 comments

Comments

@Myzel394
Copy link

  1. Added django-cors-headers and followed docs
  2. GETting, POSTing and PUTting works fine
  3. POSTing files do not work!

Here are my setting

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
ALLOWED_HOSTS = ["*"]

When I now try to upload files (Content-Type = multipart/form-data), I get the following error:

Firefox:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:3000/api/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Chrome:

Access to XMLHttpRequest at 'http://127.0.0.1:8000/api/' from origin 'http://127.0.0.1:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I checked it and indeed, the Access-Control-Allow-Origin' header is missing. I configured everything according to docs, so I think this must be an issue. Please let me know if you know a solution to this.

@adamchainz
Copy link
Owner

Closing due to age. There's not enough information here to determine the bug, but it's probably a CSRF issue. The blocked response should be read in network tools to check.

@JMIdeaMaker
Copy link

@Myzel394 did you ever solve this? I am having this issue as well

@Myzel394
Copy link
Author

Myzel394 commented Jun 18, 2021

@JMIdeaMaker I found a workaround for my case. I started chrome without security features. This way everything suddenly worked without any cors pain.

But keep in mind, that if you are using multiple domains, you still have to find a solution for this. This here will only work in development and in production when your frontend and backend is on the same domain.

EDIT
Here's the command:
google-chrome --user-data-dir="chrome_dev_session" --disable-web-security

@adamchainz
Copy link
Owner

Never EVER use Chrome with --disable-web-security, or advise others to do so.

@Myzel394
Copy link
Author

Myzel394 commented Jun 20, 2021 via email

@jassimabdullatheef
Copy link

I'm also having this issue

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

4 participants