Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

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

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 title become garbled with some kind of mixture of ascii and hex. For example ísland becomes =CDsland. Note, I am using <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> as the first value In the header. Also utf-8 works for all my other forms. Just the multipart form that becomes garbled. Anyways this is my form:

<form action="{{ uploadurl }}" enctype="multipart/form-data" method="post">
  <div><label>Title</label><input type="text" name="title" class="string" /></div>
  <div><label>Picture</label><input type="file" name="img"/></div>
  <div style="margin-top:10px;"><input type="submit" value="Add picture" /></div>
  <input type="hidden" value="{{ album.key }}" name="alid"/>
</form>

And this is the class handling the form:

# handler for posting photos
class PostPhoto(blobstore_handlers.BlobstoreUploadHandler):
    def post(self):
        upload_files =  self.get_uploads('img')
        photourl = images.get_serving_url(str(upload_files[0].key()))
        photo = Photo()
        #because of multipart/form-data
        photo.title = self.request.get("title")
        photo.photourl = photourl
        photo.photoalbum = PhotoAlbum.get(self.request.get('alid'))     
        photo.put()

Does anyone have a clue how I can fix this? Do I have to do some server side encoding/decoding? I have tried googling around for that with no results(python newb), so this is my last resort before i just alter my design and split up the forms.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...