mbraak/django-file-form

Deployment issues

mi01 opened this issue · 4 comments

mi01 commented

Hello,

thank you for contributing this nice extension. Using it in my local test environment was no problem. After deploying it to my production server I stumbled over some issues, so I want to share my experience here ...

  • I run my production environment with gunicorn and nginx. The file upload worked sometimes, but sometimes I got an error "Upload failed". This was really strange, so I started investigating. It turned out that I got sometimes a 410 response when uploaded the image with PATCH, triggered by this line:

    if filename is None or not upload_file_path.exists():

    After debugging the problem, it turned out that the filename was None when the upload failed and the filename is retrieved from the Django cache. I was using the default local-memory caching then, which is per-process. Since gunicorn was running with more than one worker process, there were cache misses sometimes. At least I think so, since the problem disappeared after configuring Memcached.

  • After solving the first problem I still got "Upload failed" sometimes. But here it was obvious, since the server response was "413 - Request Entity Too Large". Changing client_max_body_size in my nginx config solved this problem. But it would be great improvement to forward this response to the user with a dedicated error message like "File size too large!".

Maybe this obstacles should be mentioned at least in the documention?

My setup:
gunicorn 20.1.0
django-file-form 3.4.2
django 4.1.5

I'll look into it.

I added a 'production' setting to the documentation: http://mbraak.github.io/django-file-form/details/#production

The message 'file size is too large' wouldn't be correct because it's the chunk size that is too large, not the whole file size.

Background: files are uploaded using chunks of 2.5 MB.

mi01 commented

Thanks, I think this solved the deployment issues I had.