Encoding problem in app engine when submitting multipart/form-data forms

后端 未结 6 1482
别跟我提以往
别跟我提以往 2020-12-06 01:19

I have a simple form that submits a image to the blobstore and a title for the image. This works on my local devserver but when I deploy my code, non ascii letters in the ti

相关标签:
6条回答
  • 2020-12-06 02:00

    This comment explains how to fix the issue and includes the appengine_config.py, which makes everything work: http://code.google.com/p/googleappengine/issues/detail?id=2749#c21

    I don't include the code here because I have no idea how to attach file, and it's quite big to be included inline.

    0 讨论(0)
  • 2020-12-06 02:07

    =CD is the quoted-printable representation of Í.

    I have no explanation as to why the production server would be giving you this data as quoted-printable when the dev_appserver doesn't, but the quopri module from the standard library can decode it for you.

    0 讨论(0)
  • 2020-12-06 02:10

    Add the newer webob library to your app.yaml :

    libraries:
    - name: webapp2
      version: "2.5.2"
    - name: webob
      version: "1.2.3"
    

    Got it from: https://code.google.com/p/googleappengine/issues/detail?id=2749

    0 讨论(0)
  • 2020-12-06 02:14

    I'm using Django nonrel and fixed it with this middleware:

    http://code.google.com/p/googleappengine/issues/detail?id=2749#c33

    import logging
    import quopri
    log = logging.getLogger(__name__)
    
    class BlobRedirectFixMiddleware(object):
        def process_request(self, request):
            if request.method == 'POST' and 'HTTP_X_APPENGINE_BLOBUPLOAD' in request.META and request.META['HTTP_X_APPENGINE_BLOBUPLOAD'] == 'true':
                request.POST = request.POST.copy()
                log.info('POST before decoding: %s' % request.POST)
                for key in request.POST:
                    if key.startswith('_') or key == u'csrfmiddlewaretoken':
                        continue
                    value = request.POST[key]
                    if isinstance(value,(str, unicode)):
                        request.POST[key] = unicode(quopri.decodestring(value), 'iso_8859-2')
                log.info('POST after decoding: %s' % request.POST) 
            return None
    
    0 讨论(0)
  • 2020-12-06 02:14

    have you tried photourl = images.get_serving_url(unicode

    (upload_files[0].key())) insted of photourl = images.get_serving_url(str(upload_files[0].key()))

    0 讨论(0)
  • 2020-12-06 02:24

    This is a known bug. http://code.google.com/p/googleappengine/issues/detail?id=3761

    Getting back to the original data is a matter of:

    >>> import quopri
    >>> t = unicode(quopri.decodestring('=CD'), 'iso_8859-2')
    >>> print t
    Í
    
    0 讨论(0)
提交回复
热议问题