Multipart form problems with PyISAPIe and Django

Created 28th August, 2008 13:40 (UTC), last edited 28th August, 2008 14:08 (UTC)

Fairly recently Django changed the way that POST data was parsed — at least when multipart POST data is submitted (required for file uploads). PyISAPIe needs a small tweak in order for it to work with the new API.

The change that is needed is in django.core.handlers.pyisapie.PyISAPIeRequest._load_post_and_files(). It should read:

    def _load_post_and_files(This):
        "Populates This._post and This._files"
        Ctype = Env.HTTP_CONTENT_TYPE or ''
        if Ctype.startswith('multipart'):
          import StringIO
          This._post , This._files = http.HttpRequest.parse_file_upload(This, This.META, StringIO.StringIO(This.raw_post_data))
          This._post, This._files = http.QueryDict(This.raw_post_data), datastructures.MultiValueDict()

Rather surprisingly this took me about 4 hours to write, partly due to a load of incorrect comments in about which I'm going to post a ticket and a patch (which hopefully might make it in before release).