I patched appengine_config to enable foreign characters with blobstoreuploadhandler:
webapp_django_version = '1.2'
import base64
import quopri
from webob import multidict
def from_fieldstorage(cls, fs):
obj = cls()
if fs.list:
# fs.list can be None when there's nothing to parse
for field in fs.list:
if field.filename:
obj.add(field.name, field)
else:
# first, set a common charset to utf-8.
common_charset = 'utf-8'
# second, check Content-Transfer-Encoding and decode
# the value appropriately
field_value = field.value
transfer_encoding = field.headers.get(
'Content-Transfer-Encoding', None)
if transfer_encoding == 'base64':
field_value = base64.b64decode(field_value)
if transfer_encoding == 'quoted-printable':
field_value = quopri.decodestring(field_value)
if field.type_options.has_key('charset') and \
field.type_options['charset'] != common_charset:
# decode with a charset specified in each
# multipart, and then encode it again with a
# charset specified in top level FieldStorage
field_value = field_value.decode(
field.type_options['charset']).encode(common_charset)
# TODO: Should we take care of field.name here?
obj.add(field.name, field_value)
return obj
multidict.MultiDict.from_fieldstorage = classmethod(from_fieldstorage)
Now I get this error when performing an upload with a form that has just one file. Is it because I also need text values? If I remove the patch to appengine_config then my upload works but the foreign charcater breaks. Should I try adding just a hidden variable so that everyting that’s submitted isn’t just a file? Thanks for any good idea
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 703, in __call__
handler.post(*groups)
File "/base/data/home/apps/s~montaoproject/deleteoredit.354032237980992086/main.py", line 2659, in post
for upload in self.get_uploads():
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/blobstore_handlers.py", line 348, in get_uploads
for key, value in self.request.params.items():
File "/base/python_runtime/python_lib/versions/1/webob/__init__.py", line 951, in params
params = self.str_params
File "/base/python_runtime/python_lib/versions/1/webob/__init__.py", line 943, in str_params
return NestedMultiDict(self.str_GET, self.str_POST)
File "/base/python_runtime/python_lib/versions/1/webob/__init__.py", line 870, in str_POST
vars = MultiDict.from_fieldstorage(fs)
File "/base/data/home/apps/s~montaoproject/deleteoredit.354032237980992086/appengine_config.py", line 44, in from_fieldstorage
obj.add(field.name, field_value)
UnboundLocalError: local variable 'field_value' referenced before assignment
Indent “obj.add(field.name, field_value)” so that it is part of your else statement.