How do I Pass Html form image arrays to the Google App Engine(Python)?
I'm using the Python implementation of the Google App Engine. When I try to pass an array of image input tags from an html form, I can't seem to pick it up in the Python controller.
The 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>
The 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")
When I try this, I get the dreaded unicode/str error:
TypeError: Blob() argument should be str instance, not unicode
at the line where:
db.Blob(img)
I followed most of the tutorials, but none of them seemed to discuss this particular issue.
You need to include the
enctype="multipart/form-data"
attribute on your form tag, see i.e. http://www.mail-archive.com/google-appengine@googlegroups.com/msg03314.html. Googling for your error turns up several other instances of the problem.
If you still have problems once you've added the enctype
, just try db.Blob(str(img))
and / or db.Blob(img.encode('utf-8'))
as also suggested by threads like the above. You can also try images =self.request.str_GET['images']
or something similar.
精彩评论