diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py
index 40aefd6..156124a 100644
|
a
|
b
|
class MultiPartParser(object):
|
| 199 | 199 | for chunk in field_stream: |
| 200 | 200 | if transfer_encoding == 'base64': |
| 201 | 201 | # We only special-case base64 transfer encoding |
| | 202 | # We should always read base64 streams by multiple of 4 |
| | 203 | over_bytes = len(chunk) % 4 |
| | 204 | if over_bytes: |
| | 205 | over_chunk = field_stream.read(4 - over_bytes) |
| | 206 | chunk += over_chunk |
| | 207 | |
| 202 | 208 | try: |
| 203 | 209 | chunk = base64.b64decode(chunk) |
| 204 | 210 | except Exception as e: |
diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py
index 2a1ec7d..4ee7c18 100644
|
a
|
b
|
class FileUploadTests(TestCase):
|
| 60 | 60 | |
| 61 | 61 | self.assertEqual(response.status_code, 200) |
| 62 | 62 | |
| 63 | | def test_base64_upload(self): |
| 64 | | test_string = "This data will be transmitted base64-encoded." |
| | 63 | def _test_base64_upload(self, content): |
| 65 | 64 | payload = "\r\n".join([ |
| 66 | 65 | '--' + client.BOUNDARY, |
| 67 | 66 | 'Content-Disposition: form-data; name="file"; filename="test.txt"', |
| 68 | 67 | 'Content-Type: application/octet-stream', |
| 69 | 68 | 'Content-Transfer-Encoding: base64', |
| 70 | 69 | '', |
| 71 | | base64.b64encode(force_bytes(test_string)).decode('ascii'), |
| | 70 | base64.b64encode(force_bytes(content)).decode('ascii'), |
| 72 | 71 | '--' + client.BOUNDARY + '--', |
| 73 | 72 | '', |
| 74 | 73 | ]).encode('utf-8') |
| … |
… |
class FileUploadTests(TestCase):
|
| 82 | 81 | response = self.client.request(**r) |
| 83 | 82 | received = json.loads(response.content.decode('utf-8')) |
| 84 | 83 | |
| 85 | | self.assertEqual(received['file'], test_string) |
| | 84 | self.assertEqual(received['file'], content) |
| | 85 | |
| | 86 | def test_base64_upload(self): |
| | 87 | self._test_base64_upload("This data will be transmitted base64-encoded.") |
| | 88 | |
| | 89 | def test_big_base64_upload(self): |
| | 90 | self._test_base64_upload("Big data" * 68000) # > 512Kb |
| 86 | 91 | |
| 87 | 92 | def test_unicode_file_name(self): |
| 88 | 93 | tdir = tempfile.gettempdir() |