alican / django-tus

Django app implementing server side of tus protocol to powering resumable file uploads for django projects. More Info about: http://tus.io/
MIT License
49 stars 32 forks source link

Upload is fine, but resuming a paused upload is not working #6

Open guilhermej opened 6 years ago

guilhermej commented 6 years ago

I'm trying to use your module with my Django and Uppy like the frontend uploader, using the TUS protocol. The upload is OK, but when I try to pause and resume the upload something wrong happens, the upload of the file restarts from beginning. The behavior I can notice is:

  1. Uppy makes the post to start the upload
  2. Uppy makes a patch to upload the file
  3. When I pause, the patch requisition is cancelled
  4. When I click in resume, Uppy makes a head requisition but the offset returned is 0
  5. Makes a patch, but starting from 0.

Can you help me to find the problem?

nagarjunbn commented 6 years ago

same problem here with Django version: 2.10 . tusjs client which is working correctly with nodejs server given by tus but not working with django server .

guilhermej commented 6 years ago

I was able to make it work in the local Django server by editing the code in patch method in the views.py:

finally:
    file.seek(file_offset)
    file.write(request.body)
    file.close()

I add the line chunk_size = len(request.body)

The final code is this:

finally:
    file.seek(file_offset)
    file.write(request.body)
    chunk_size = len(request.body)
    file.close()

This is working just in the local Django server, but this not work in Apache/WSGI production server, because when pause the upload, the connection is closed and Django raises a UnreadablePostError, and the patch method is not called, so I will try in another type of server like a Nginx/Gunicorn.

P.S.: I'm using the GIT code, not the pip module.