我尝试使用以下 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/