python - 谷歌应用引擎+ python : uploading to blobstore causes wrong encoding

标签 python google-app-engine blobstore

我尝试使用以下 HTML 表单将 blob 上传到 Google App Engine 的 blobstore:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
</head>
<body>
<form id=upload action={{upload_url}} method=post enctype=multipart/form-data>
  Name: <input type=text name=name>
  Your photo: <input type=file name=image required=required><br><br>
  <input type=submit value=submit>
</form>
</body>
</html>

模板变量{{upload_url}}的值是在服务器端通过upload_url = blobstore.create_upload_url('/upload')获取的。后处理脚本如下:

    class Test(ndb.Model):
        name = StringProperty()
        image = StringProperty()

    test = Test()
    test.name = self.request.get('name')
    image = self.get_uploads('image')[0]
    test.image = str(image.key())
    test.put()

通常,名称字段将填充非英文字符(例如中文)。上述程序在我的本地 SDK 上运行良好。但是,当程序在 Google App Engine 上运行时,名称 的编码不正确。那么问题出在哪里呢?

最佳答案

您是否必须在元标记参数周围加上引号:<meta charset="UTF-8"> ?另外,请尝试:<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 。并且,请确保您以 UTF-8 编码保存模板的文本文档。

关于python - 谷歌应用引擎+ python : uploading to blobstore causes wrong encoding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23956364/

相关文章:

java - 使用 Google Account UserService 时如何更新 App Engine 应用程序名称

google-app-engine - Google Blobstore 与 Google Cloud Storage

python - 如何替换 spark 数据框所有列中的多个字符?

google-app-engine - 转换 Appscript 实例以在 Appengine 中运行

java - POJO 到 Google App Engine 中的 XML 字符串?

python - GAE blobstore文件名UTF-8编码问题

google-app-engine - GWT FormPanel 在 GWT 版本 2.4.0 上更新后不提交 session ID

python - 赋值之前引用的局部变量。 Python

python - 使用 Pandas 计算重复项之间的交集

python - 查询集注释中的动态字段名称