Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileUploadParser not compatible with Django Upload Handlers #4292

Closed
6 tasks done
cyalangi opened this issue Jul 21, 2016 · 4 comments
Closed
6 tasks done

FileUploadParser not compatible with Django Upload Handlers #4292

cyalangi opened this issue Jul 21, 2016 · 4 comments

Comments

@cyalangi
Copy link

cyalangi commented Jul 21, 2016

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

  • Define a POST view to use FileUploadParser
  • Use curl to upload a 100 byte text/plain file.
    The line 149 in parsers.py is buggy. It is expecting a return value from handle_raw_input. MemoryFileUploadHandler::handle_raw_input() doesn't return anything. Django FileUploadHandler::handle_raw_input() doesn't return any value.

Expected behavior

Handle the uploaded file

Actual behavior

Throws the following error
FileUpload parse error - none of upload handlers can handle the stream

@xordoquy
Copy link
Collaborator

You'll need to be more specific with your curl commande as it's probably sent as multipart

@cyalangi
Copy link
Author

cyalangi commented Jul 21, 2016

The request body was not sent as multipart. Here is the curl command I used.

curl -X POST http://localhost:8000/internal -H "Content-Type: text/plain; chartset utf-8" -H "TOKEN: ###" --data-binary @./datafile.csv

Here is the corresponding HTTP request

* Connected to localhost (127.0.0.1) port 8000 (#0)
> POST /internal HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.43.0
> Accept: */*
> TOKEN: ###
> Content-Type: text/plain; charset=utf-8
> Content-Length: 328
> 

If you refer to the code line I mentioned in the bug description you can see that handle_raw_input() doesn't return any values.

@tomchristie
Copy link
Member

tomchristie commented Aug 1, 2016

Note that our behavior of handle_raw_input is based on Django's.

REST framework: https://github.com/tomchristie/django-rest-framework/blob/3.4.1/rest_framework/parsers.py#L149
Django: https://github.com/django/django/blob/1.9.8/django/http/multipartparser.py#L128

Tho ticket may still need further review before resolution.

@tomchristie
Copy link
Member

This is actually caused by a different issue than originally reported. Believe this to in fact be a duplicate of #3610.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants