juliomalegria / django-chunked-upload

Upload large files to Django in multiple chunks, with the ability to resume if the upload is interrupted.
MIT No Attribution
214 stars 71 forks source link

Release 1.1.2 not working on uWSGI and gunicorn #33

Closed morenosan closed 7 years ago

morenosan commented 7 years ago

Hi!

Thank you for sharing this package. It's really useful.

I've found a problem upgrading to the 1.1.2 release. Using runserver works great, but at least on uWSGI and gunicorn, it fails with the following error just after receiving the first chunk.

[2017-06-22 10:03:41,866] ERROR django.request-132 Internal Server Error: /api/chunked_upload/
Traceback (most recent call last):
  File "/home/juan/.virtualenvs/demo/lib/python3.5/site-packages/django/core/handlers/exception.py", line 42, in inner
    response = get_response(request)
  File "/home/juan/.virtualenvs/demo/lib/python3.5/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/juan/.virtualenvs/demo/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/juan/.virtualenvs/demo/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/juan/.virtualenvs/demo/lib/python3.5/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/juan/.virtualenvs/demo/lib/python3.5/site-packages/chunked_upload/views.py", line 93, in post
    return self._post(request, *args, **kwargs)
  File "/home/juan/.virtualenvs/demo/lib/python3.5/site-packages/chunked_upload/views.py", line 214, in _post
    chunked_upload.append_chunk(chunk, chunk_size=chunk_size, save=False)
  File "/home/juan/.virtualenvs/demo/lib/python3.5/site-packages/chunked_upload/models.py", line 69, in append_chunk
    self.file.write(chunk.read())
io.UnsupportedOperation: write

Same code with release 1.1.1 works as expected I've tested it with uWSGI-2.0.14 and gunicorn-19.7.1

Flinkas commented 7 years ago

Did you check the read/write permissions?

morenosan commented 7 years ago

Yes. In the following code:

    def append_chunk(self, chunk, chunk_size=None, save=True):
        self.file.close()
        self.file.open(mode='ab')  # mode = append+binary

First line closes the file. But the second line opens the file in read mode, not in 'ab' mode, as requested.

kansch commented 7 years ago

Same issue, with 1.1.2 and using runserver (Django 1.9.7):

 File "<path_to_virtualenv>/lib/python3.5/site-packages/chunked_upload/models.py", line 69, in append_chunk
    self.file.write(chunk.read())
io.UnsupportedOperation: write

I juste tested the 1.1.1 and it works.

kansch commented 7 years ago

Version 1.1.2 works with Django 1.11.0. Apparently it was due to this bug:

https://code.djangoproject.com/ticket/13809

Fixed by:

https://github.com/django/django/commit/ac1975b18b5a33234284bec86e5a5bb44a4af976

morenosan commented 7 years ago

Thanks @kansch!

The problem was the Django version. Updating from 1.10 to 1.11 fixed the problem.