Re: Should Django handle uploaded files in PUT as well as POST?
On Sat, Jan 16, 2010 at 6:32 AM, Malcolm Box <malcolm.box@gmail.com> wrote:
> Hi,
>
> I'm working on a REST-full API that allows an uploaded file to be PUT to a
> URL. I also need to support the X-Http-Method-Override header to turn a
> POST request into a PUT for clients (Flash, mobile etc) that can't do PUT.
>
> At the moment I've got the API working with POST requests, and am now moving
> over to PUT + implementing the override.
>
> I'm running into several places where it seems Django processes things
> differently if they come from a POST or a PUT. The most obvious is the
> HttpRequest (and derived classes) handling of _load_post_and_files(). This
> parses a multipart upload into a set of files in request.FILES and the rest
> of the POST data into request.POST, whenever request.POST is accessed.
>
> However a similar transformation isn't applied to PUT requests - so
> accessing request.FILES finds nothing there, and there's no equivalent
> request.PUT.
>
> Django-rest-interface
> (http://code.google.com/p/django-rest-interface/wiki/RestifyDjango) gets
> round this by looking for PUT requests, then calling
> request._load_post_and_files() directly to populate the FILES member.
>
> This seems very brittle if anything goes near request.POST before the rest
> interface runs, since the request.POST access will parse the uploaded data
> which is then not available for reparsing - error messages such as "Cannot
> read more than the available bytes from the HTTP incoming data" then pop up.
>
> It seems to me that Django should process POST and PUT requests the same -
> i.e. the request.FILES attribute should be initialised for either if a
> multipart content-type is detected.
>
> Have I fundamentally misunderstood how this stuff should work?
On first inspection, I don't think you've got anything fundamentally
wrong. Support for PUT and the other 'exotic' HTTP request methods is
one area where Django support is a little bit patchy.
This is mostly an artefact of the vast majority of browsers providing
exactly zero support for requests other that GET and POST. As a result
Django is (by necessity) really good at handling GET and POST; PUT,
DELETE et al are all essential parts of the full HTTP spec, but
support in Django isn't quite as comprehensive.
This is one of those areas where patches are definitely welcome.
Yours,
Russ Magee %-)
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home