我正在尝试在 Django 中执行此操作(将画布异步上传为图像文件)。我正在使用演示中的 javascript(稍作修改的版本),它滚动了自己的 XHRHttpRequest,但我无法在服务器端找到上传的任何证据。
画布数据是这样提取的:
img_data = canvas.toDataURL('image/jpeg').replace("data:image/jpeg;base64,", "");
这是 xhr 标头:
xhr.setRequestHeader('content-type', 'multipart/form-data; boundary=multipartformboundary1352769538973');
这是 POST 内容:
--multipartformboundary1352769538973
Content-Disposition: form-data; name="user_file"; filename="test.jpeg"
Content-Type: application/octet-stream
/9j/4AAQSkZJRgABAgAAAQABAAD/2wCEAAUDAwUHD...snipping image data...
AJRRRQAUtJS018gA/9k=
--multipartformboundary1352769538973
Content-Disposition: form-data; name="username"
--multipartformboundary1352769538973
Content-Disposition: form-data; name="challenge"
--multipartformboundary1352769538973
Content-Disposition: form-data; name="galleryPath"
--multipartformboundary1352769538973--
当我让 Django 向我展示它看到的请求对象时,这就是我得到的:
<WSGIRequest
path:/samlite/save_frame,
GET:<QueryDict: {}>,
POST:<QueryDict: {u'username': [u''], u'challenge': [u''], u'galleryPath': [u'']}>,
COOKIES:{},
META:{'ARCHFLAGS': '-arch i386',
'Apple_PubSub_Socket_Render': '/tmp/launch-wL0OpX/Render',
'Apple_Ubiquity_Message': '/tmp/launch-ox20mG/Apple_Ubiquity_Message',
'COMMAND_MODE': 'unix2003',
'CONTENT_LENGTH': '34323',
'CONTENT_TYPE': 'multipart/form-data; boundary=multipartformboundary1352769538973',
'DISPLAY': '/tmp/launch-KzsfWx/org.x:0',
'DJANGO_SETTINGS_MODULE': 'simsam.settings',
'DYLD_LIBRARY_PATH': '/Applications/bitnami-djangostack/apps/django/lib/python2.7/site-packages:/Applications/bitnami-djangostack/apps/django/lib/python2.7/site-packages:/Applications/bitnami-djangostack/python/lib:/Applications/bitnami-djangostack/mysql/lib:/Applications/bitnami-djangostack/sqlite/lib:/Applications/bitnami-djangostack/apache2/lib:/Applications/bitnami-djangostack/common/lib:',
'GATEWAY_INTERFACE': 'CGI/1.1',
'HOME': '/Users/chris',
'HTTP_ACCEPT': 'text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1',
'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
'HTTP_ACCEPT_LANGUAGE': 'en,en-US;q=0.9,ja;q=0.8,fr;q=0.7,de;q=0.6,es;q=0.5,it;q=0.4,pt;q=0.3,pt-PT;q=0.2,nl;q=0.1',
'HTTP_CONNECTION': 'Keep-Alive',
'HTTP_HOST': 'localhost:8000',
'HTTP_REFERER': 'http://localhost:8000/samlite/',
'HTTP_USER_AGENT': 'Opera/9.80 (Macintosh; Intel Mac OS X 10.7.5) Presto/2.12.388 Version/12.10',
'LANG': 'en_US.UTF-8',
...less interesting stuff snipped...
}>
所以正常的 POST 键/值对正在通过,但基于此,我希望看到一个 response.FILES 字典。谁能指出我正确的方向?