【发布时间】:2011-08-02 04:30:48
【问题描述】:
我正在使用 Google App Engine 的 Python 实现。当我尝试从 html 表单传递图像输入标签数组时,我似乎无法在 Python 控制器中获取它。
HTML:
<form action="/addImages" method="post" enctype="multipart/form-data">
<input type="file" name="images" />
<input type="file" name="images" />
<input type="file" name="images" />
</form>
Python:
class AddImages(webapp.RequestHandler):
def post(self):
images = self.request.get_all('images')
for img in images:
if img != None:
img_entity.blob = db.Blob(img)
self.response.out.write("Upload Succeeded")
当我尝试这个时,我得到了可怕的 unicode/str 错误:
TypeError: Blob() argument should be str instance, not unicode
在哪里:
db.Blob(img)
我遵循了大部分教程,但似乎都没有讨论这个特定问题。
【问题讨论】:
-
你试过
img.encode()db.Blob()吗? -
我可以将 unicode 编码为 utf-8 或 ascii,但这不会丢弃一些文件数据吗?
-
您知道,如果您尝试在所有字段中上传超过 10MB 的数据,您将会遇到过大的请求,对吧?我建议使用 BlobStore。它让很多这种头痛消失了。
标签: python html google-app-engine forms http-post