I want to upload large files to my djangos MEDIA folder using the nginx upload module.
The Django REST "POST" endpoint for the single file upload is at
http://localhost:1337/api/record/measurements/#id/upload/
where #id can be an integer (1,2,3,4,5...), and works for django without nginx.
I wrote the nginx config
#/etc/nginx/conf.d/default.conf
location @backend {
proxy_pass http://django-app:8000;
}
location /api/record/measurements/1/upload/ {
error_page 418 = @upload;
if ($request_method = POST ) {
return 418;
}
include /etc/nginx/mainloc.conf;
}
location @upload {
upload_pass @backend;
upload_store /vol/web/media/_upload 1;
upload_store_access user:r;
upload_set_form_field $upload_field_name.name "$upload_file_name";
upload_set_form_field $upload_field_name.content_type "$upload_content_type";
upload_set_form_field $upload_field_name.path "$upload_tmp_path";
upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
upload_pass_form_field "^submit$|^description$";
upload_cleanup 400 404 499 500-505;
}
location / {
include /etc/nginx/mainloc.conf;
}
with
#mainloc.conf
proxy_pass http://django-app:8000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
I managed to upload the file to /vol/web/media/_upload, but after the file upload is complete, I get the response
{
"id": 1,
"data": null
}
and the uploaded File is not moved to the final location MEDIA=/vol/web/media/ but remains in upload_store