Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Should Django handle uploaded files in PUT as well as POST?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Malcolm Box  
View profile  
 More options Jan 15 2010, 5:32 pm
From: Malcolm Box <malcolm....@gmail.com>
Date: Fri, 15 Jan 2010 22:32:00 +0000
Subject: Should Django handle uploaded files in PUT as well as POST?

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?

Cheers,

Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Russell Keith-Magee  
View profile  
 More options Jan 15 2010, 11:58 pm
From: Russell Keith-Magee <freakboy3...@gmail.com>
Date: Sat, 16 Jan 2010 12:58:44 +0800
Local: Fri, Jan 15 2010 11:58 pm
Subject: Re: Should Django handle uploaded files in PUT as well as POST?

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 %-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Box  
View profile  
 More options Jan 17 2010, 7:14 pm
From: Malcolm Box <malcolm....@gmail.com>
Date: Mon, 18 Jan 2010 00:14:39 +0000
Local: Sun, Jan 17 2010 7:14 pm
Subject: Re: Should Django handle uploaded files in PUT as well as POST?

On Sat, Jan 16, 2010 at 4:58 AM, Russell Keith-Magee <freakboy3...@gmail.com

way to go.

Which raises the question of what the correct behaviour should be, so the
bug can report that it's not happening and the patch can implement.

As a first pass:

"On a PUT request, Django should populate request.PUT and request.FILES in
the same way as for POST requests.  FILES will be initialised if the content
is multipart, and the PUT dictionary will have key/value pairs if the
uploaded content included url-encoded form entries.

If the format of the datastream is not understood, it will be left in
_raw_post_data as previously, and req.FILES and req.PUT initialised to empty
hashes."

Does this sound reasonable as a bug/feature description?

Cheers,

Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Russell Keith-Magee  
View profile  
 More options Jan 17 2010, 9:04 pm
From: Russell Keith-Magee <freakboy3...@gmail.com>
Date: Mon, 18 Jan 2010 10:04:04 +0800
Local: Sun, Jan 17 2010 9:04 pm
Subject: Re: Should Django handle uploaded files in PUT as well as POST?

As always.

> Which raises the question of what the correct behaviour should be, so the
> bug can report that it's not happening and the patch can implement.

> As a first pass:

> "On a PUT request, Django should populate request.PUT and request.FILES in
> the same way as for POST requests.  FILES will be initialised if the content
> is multipart, and the PUT dictionary will have key/value pairs if the
> uploaded content included url-encoded form entries.

> If the format of the datastream is not understood, it will be left in
> _raw_post_data as previously, and req.FILES and req.PUT initialised to empty
> hashes."

> Does this sound reasonable as a bug/feature description?

Sounds reasonable to me. I can't think of any obvious reason that the
handling for PUT should differ from POST.

Yours,
Russ Magee %-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Box  
View profile  
 More options Jan 18 2010, 4:10 am
From: Malcolm Box <malcolm....@gmail.com>
Date: Mon, 18 Jan 2010 09:10:40 +0000
Local: Mon, Jan 18 2010 4:10 am
Subject: Re: Should Django handle uploaded files in PUT as well as POST?

On Mon, Jan 18, 2010 at 2:04 AM, Russell Keith-Magee <freakboy3...@gmail.com

Ticket http://code.djangoproject.com/ticket/12635 raised.  Patches to
follow.

Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Masklinn  
View profile  
 More options Jan 18 2010, 4:23 am
From: Masklinn <maskl...@masklinn.net>
Date: Mon, 18 Jan 2010 10:23:02 +0100
Local: Mon, Jan 18 2010 4:23 am
Subject: Re: Should Django handle uploaded files in PUT as well as POST?
On 18 Jan 2010, at 03:04 , Russell Keith-Magee wrote:

Does that mean the request object could have arbitrary HTTP_METHOD attributes when it can parse the content as keys:values? At least if the MIME of the request is `application/x-www-form-urlencoded`?

I mean as far as I know nothing forbids creating custom HTTP methods (indeed, that's what e.g. WEBDAV does) and some of these custom methods could very well have the same properties as POST.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Box  
View profile  
 More options Jan 18 2010, 6:29 am
From: Malcolm Box <malcolm....@gmail.com>
Date: Mon, 18 Jan 2010 11:29:51 +0000
Local: Mon, Jan 18 2010 6:29 am
Subject: Re: Should Django handle uploaded files in PUT as well as POST?

I don't see why not, although that's not what I'm planning to submit patches
for - I'm just aiming to cover PUT ie to complete the support for the core
HTTP methods that are allowed entity bodies.

So the HttpRequest object will grow a new PUT attribute, but nothing else.

Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Russell Keith-Magee  
View profile  
 More options Jan 18 2010, 10:31 am
From: Russell Keith-Magee <freakboy3...@gmail.com>
Date: Mon, 18 Jan 2010 23:31:41 +0800
Local: Mon, Jan 18 2010 10:31 am
Subject: Re: Should Django handle uploaded files in PUT as well as POST?

FYI, Section 5.1.1 of RFC 2616 specifically allows the definition of
extension methods.

I'm open to suggestions on how Django's handling of arbitrary
extension methods can be improved. As it stands, request.REQUEST will
contain all the query arguments that have been provided in a request,
regardless of the request method. This can already be used to support
extension request methods.

If you're looking for something more than this, feel free to make a
specific proposal. Personally I'm not sure I agree that having
request.FOOBAR is a good idea. There are many names that are legal
request methods, but aren't legal variable names, so we would need to
have a mapping scheme. We would also end up with a situation where
extension methods would only produce attributes when used, so
hasatttr(request, 'POST') would always succeed, but hasattr(request,
'FOOBAR') would only succeed if request.method == 'FOOBAR'.

However, as Malcolm notes - this is a separate issue to handling FILES
on a PUT request, so it should be handled as a separate ticket and
mailing list thread.

Yours,
Russ Magee %-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »