I'm running a Django server hosted on DigitalOcean using Nginx and Gunicorn. I tried adding a 2MB picture via the admin interface when I get hit with a 403 error. Looking into error.log
indicated permission was denied, as follows:
2017/06/27 01:03:29 [error] 1643#1643: *30 open() "/home/brian/nydkc11/nydkc11/nydkcd11/media/image_main/dtc1.jpg" failed (13: Permission denied), client: 108.29.217.25, server: nydkc11.org, request: "GET /media/image_main/dtc1.jpg HTTP/1.1", host: "nydkc11.org", referrer: "http://nydkc11.org/admin/blog/image/7/change/"
The weirdest thing, however, is that smaller image files work just fine (around 18 kb or so). Anyone know why larger media files may be triggering the problem, and how I should fix it?
I had to set client_max_body_size
to 100M
in my nginx.conf
, if that's a useful thing to know.
I just came across the exact same problem. Thanks for your SO thread, otherwise I'd still be searching in the wrong place.
To fix this, you actually do not need to set DATA_UPLOAD_MAX_MEMORY_SIZE
as long as you're only experiencing this error when uploading files. The Django documentation links to the other value, FILE_UPLOAD_MAX_MEMORY_SIZE
, here.
Setting FILE_UPLOAD_MAX_MEMORY_SIZE
to a higher limit in my settings.py
resolves the problem, alongside with the aforementioned client_max_body_size
in nginx.conf
.
This sets the upload maximum to roughly 200 MB
:
FILE_UPLOAD_MAX_MEMORY_SIZE = 200000000
larger files(>2.5M) are stored using temporary files, which will get 0o600 permissions by default. The problem can easily be fixed by setting a value to FILE_UPLOAD_PERMISSIONS
Set this in settings.py
FILE_UPLOAD_PERMISSIONS = 0o644
Reference
See For Python2
See Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With