mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #11159 -- Added mimetype detection to the test client for file uploads. Thanks to notanumber for the report and patch, and lomin for the test case.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13517 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -3,6 +3,7 @@ from urlparse import urlparse, urlunparse, urlsplit
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import mimetypes
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
@@ -138,11 +139,14 @@ def encode_multipart(boundary, data):
|
||||
|
||||
def encode_file(boundary, key, file):
|
||||
to_str = lambda s: smart_str(s, settings.DEFAULT_CHARSET)
|
||||
content_type = mimetypes.guess_type(file.name)[0]
|
||||
if content_type is None:
|
||||
content_type = 'application/octet-stream'
|
||||
return [
|
||||
'--' + boundary,
|
||||
'Content-Disposition: form-data; name="%s"; filename="%s"' \
|
||||
% (to_str(key), to_str(os.path.basename(file.name))),
|
||||
'Content-Type: application/octet-stream',
|
||||
'Content-Type: %s' % content_type,
|
||||
'',
|
||||
file.read()
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user