NattyP
NattyP

Reputation: 163

413 Payload Too Large on Django server

My team has been getting 413 errors whenever we try and upload large files to our Django back-end: 413 Payload too large

We can't exactly pin down the maximum acceptable file size - it seems to vacillate in the 1-3MB range.

Things we have excluded:

Can anyone spot what we're missing?

Upvotes: 12

Views: 9449

Answers (3)

Dabble
Dabble

Reputation: 184

If your team was/is using Django Channels, there was a piece of code introduced in 2.1.7 causing an unintended 413 error (discussed here). This was fixed in 2.3.0, however.

Upvotes: 4

Martin Janeček
Martin Janeček

Reputation: 585

Django has a build in mechanism to prevent any suspicious activity.

In your settings.py file set the variable

DATA_UPLOAD_MAX_MEMORY_SIZE = 10*1024*1024  # your size limit in bytes

See documentation: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-DATA_UPLOAD_MAX_MEMORY_SIZE

Upvotes: 19

William R. Marchand
William R. Marchand

Reputation: 588

As far as I know runserver or daphne will never return a 413. Looks like you have NGINX in front of the python server.

You can change the limit with client_max_body_size in the server block in nginx.conf

    server {
        client_max_body_size 20M;
        listen       80;
        server_name  localhost;
        location / {
            proxy_pass         http://127.0.0.1:8000/;
        }
    }

Upvotes: 4

Related Questions