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

500 error on patch request #16

Closed RubenGarcia closed 3 years ago

RubenGarcia commented 4 years ago

Description

The following request

curl -i -H "Authorization: Bearer $1" \
    -H "tus-resumable: 1.0.0" \
    -H "upload-offset: 0" \
    -H "content-type: application/offset+octet-stream " \
    --data-binary "@file" \
    -X PATCH \
    https://<host>/upload/2ecff761-5da5-4f34-86a8-efa7ea8a2b49

produces

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

which eventually ends up as a 500 Internal Server Error instead of 204 or 404. I don't think there is an issue with the request itself, but if there is, I think you should return 400 Bad Request here.

The line producing the error is tusfile.py line 60

self.file_size = int(cache.get("tus-uploads/{}/file_size".format(resource_id)))

What I Did

curl -i -H "Authorization: Bearer $1" \
    -H "tus-resumable: 1.0.0" \
    -H "upload-offset: 0" \
    -H "content-type: application/offset+octet-stream " \
    --data-binary "@file" \
    -X PATCH \
    https://<host>/upload/2ecff761-5da5-4f34-86a8-efa7ea8a2b49

produced

HTTP/1.1 100 Continue^M
^M
HTTP/1.1 500 Internal Server Error^M 
...
alican commented 3 years ago

@RubenGarcia Hey, can you check if the bug is fixed? I think you get the error because their was no check if the resource_id exists. Now I added a check and it will raise an 404 error if its not found.

RubenGarcia commented 3 years ago

I will check it after the holidays, but in principle that looks like a good solution.