diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py
index e45d5d1..ae143f7 100644
a
|
b
|
class MultiPartParser(object):
|
145 | 145 | continue |
146 | 146 | |
147 | 147 | transfer_encoding = meta_data.get('content-transfer-encoding') |
| 148 | if transfer_encoding is not None: |
| 149 | transfer_encoding = transfer_encoding[0].strip() |
148 | 150 | field_name = force_unicode(field_name, encoding, errors='replace') |
149 | 151 | |
150 | 152 | if item_type == FIELD: |
diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py
index 5da0a5f..3c126b7 100644
a
|
b
|
|
1 | 1 | #! -*- coding: utf-8 -*- |
2 | 2 | |
| 3 | import base64 |
3 | 4 | import errno |
4 | 5 | import hashlib |
5 | 6 | import os |
… |
… |
class FileUploadTests(TestCase):
|
56 | 57 | |
57 | 58 | self.assertEqual(response.status_code, 200) |
58 | 59 | |
| 60 | def test_base64_upload(self): |
| 61 | test_string = "This data will be transmitted base64-encoded." |
| 62 | payload = "\r\n".join([ |
| 63 | '--' + client.BOUNDARY, |
| 64 | 'Content-Disposition: form-data; name="file"; filename="test.txt"', |
| 65 | 'Content-Type: application/octet-stream', |
| 66 | 'Content-Transfer-Encoding: base64', |
| 67 | '', |
| 68 | base64.b64encode(test_string), |
| 69 | '--' + client.BOUNDARY + '--', |
| 70 | '', |
| 71 | ]) |
| 72 | r = { |
| 73 | 'CONTENT_LENGTH': len(payload), |
| 74 | 'CONTENT_TYPE': client.MULTIPART_CONTENT, |
| 75 | 'PATH_INFO': "/file_uploads/echo_content/", |
| 76 | 'REQUEST_METHOD': 'POST', |
| 77 | 'wsgi.input': client.FakePayload(payload), |
| 78 | } |
| 79 | response = self.client.request(**r) |
| 80 | received = simplejson.loads(response.content) |
| 81 | |
| 82 | self.assertEqual(received['file'], test_string) |
| 83 | |
59 | 84 | def test_unicode_file_name(self): |
60 | 85 | tdir = tempfile.gettempdir() |
61 | 86 | |
diff --git a/tests/regressiontests/file_uploads/urls.py b/tests/regressiontests/file_uploads/urls.py
index 413080e..9f814c4 100644
a
|
b
|
urlpatterns = patterns('',
|
6 | 6 | (r'^verify/$', views.file_upload_view_verify), |
7 | 7 | (r'^unicode_name/$', views.file_upload_unicode_name), |
8 | 8 | (r'^echo/$', views.file_upload_echo), |
| 9 | (r'^echo_content/$', views.file_upload_echo_content), |
9 | 10 | (r'^quota/$', views.file_upload_quota), |
10 | 11 | (r'^quota/broken/$', views.file_upload_quota_broken), |
11 | 12 | (r'^getlist_count/$', views.file_upload_getlist_count), |
diff --git a/tests/regressiontests/file_uploads/views.py b/tests/regressiontests/file_uploads/views.py
index 0fd0b65..dba7522 100644
a
|
b
|
def file_upload_echo(request):
|
85 | 85 | r = dict([(k, f.name) for k, f in request.FILES.items()]) |
86 | 86 | return HttpResponse(simplejson.dumps(r)) |
87 | 87 | |
| 88 | def file_upload_echo_content(request): |
| 89 | """ |
| 90 | Simple view to echo back the content of uploaded files for tests. |
| 91 | """ |
| 92 | r = dict([(k, f.read()) for k, f in request.FILES.items()]) |
| 93 | return HttpResponse(simplejson.dumps(r)) |
| 94 | |
88 | 95 | def file_upload_quota(request): |
89 | 96 | """ |
90 | 97 | Dynamically add in an upload handler. |