﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15496	"""Content-Transfer-Encoding: base64"" not honored when uploading files"	gene@…	nobody	"When the client POST-s a file in base64 encoding, Django does not decode the file correctly.

== How to Repeat ==

Upload a file to a Django view in an HTML form with method=""POST"" and enctype=""multipart/form-data""; inside the MIME part for the file, encode the body in base64 and indicate the encoding in the Content-Transfer-Encoding: header.

== Expected Result ==

The uploaded file, when examined on disk, is decoded (by Django).

== Actual Result ==

The uploaded file, when examined on disk, is still base64-encoded.

== Analysis ==

In module {{{django.http.multipartparser}}}, {{{MultiPartParser.parse()}}} iterates over each part as returned by a {{{Parser}}} object.  The {{{Parser}}} object yields a header dictionary, which {{{MultiPartParser.parse()}}} captures in {{{meta_data}}}.  {{{parse()}}} then fetches the Content-Transfer-Encoding header from {{{meta_data}}} into {{{transfer_encoding}}}.

{{{transfer_encoding}}}, as returned by {{{meta_data.get()}}}, is not simply a string such as {{{'base64'}}} but really a 2-tuple (value, params).  Also, the header value (the first element of the returned tuple) is not whitespace-trimmed.

As a result, if the part contained {{{'Content-Transfer-Encoding: base64'}}}, {{{meta_data.get('Content-Transfer-Encoding')}}} does not return just {{{'base64'}}} but a 2-tuple {{{(' base64', {})}}}:

* The header has no parameters, hence an empty parameter dictionary;
* The value portion retains the leading space, right after the colon (:) in the raw header.

{{{parse()}}} needs the whitespace-trimmed version of the first element of the tuple; the attached patch converts the returned tuple into the string."	Bug	closed	HTTP handling	dev	Normal	fixed	base64 file upload	Tom Christie	Ready for checkin	1	0	0	0	0	0
