Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add a FileUpload parser. #7

tomchristie opened this Issue · 6 comments

3 participants


It'd be great to have a parser class that handled PUTing binary data and treating it as a file upload.

I've discussed this in a question on stackoverflow, and almost everything needed to get this task done ought to
be outlined there...


Pasting this in from IRC for the record.

[10:55:06] "If a binary PUT request is parsed can I assume that data will be None and files should contain the uploaded file as a list ?"
[10:55:24] You'll be returning a two-tuple of (data,files)
[10:55:29] data should be an empty dict
[10:55:44] files should be a dict with a single key/val
[10:56:08] key: filename
[10:56:13] val: UploadedFile instance
[10:56:39] ic, thanks! I'll paste that somewhere so I'll remember when I start implementing.


I'll be tackling this one!


@jonasgeiregat - I'll need to tweak the parser_context dict slightly to make this happen.
Will add the following keys:

  • view
  • args
  • kwargs

Note that I may also drop meta and upload_handlers, and in preference of simply adding request instead.

I reckon the most sensible thing to do for determining the filename of the upload would be to:

  1. Default to checking the view kwargs for filename, and use that if it exists (ie developer includes a 'pathname' arg in the URLConf)
  2. Fall back to expecting a 'Content-Disposition filename=...' header see RFC2616.
  3. Otherwise, fail raising ParseError('Cannot determine filename, expected Content-Disposition header') or something like that.

Hey guys,

is it correct that the current ModelSerializers don't support File- and ImageFields yet? If so, how can I be of any help?


@markotibold - Correct. If you wanna tackle it we'd need FileFields and ImageFields (as a new ticket).
You'll probably need to make a minor API change in order to support them - field_from_native will need to take a files argument as well as the existing data argument.



@wronglink wronglink referenced this issue from a commit in wronglink/django-rest-framework
@wronglink wronglink Added FileUploadParser refs #7 0c85768
@tomchristie tomchristie closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.