Getting the name & extension of an uploaded file using python (google app engine)

假如想象 提交于 2019-12-05 14:34:42

Does the snippet from this email work?

 self.request.params[<form element name with file>].filename

Try this...

If your form looks like this:

self.response.out.write('''<form action="/upload" enctype="multipart/form-data" method="post"><input type="file" name="file"/><input type="submit" /></form>''')

Then in your post handler, try this:

class UploadHandler(webapp.RequestHandler):     
    def post(self):
        obj = MyModel()
        obj.filename = self.request.get("file")
        obj.blob = self.request.get("contents")
        obj.put()
        self.redirect('/')

The filename is stored in the "file" parameter. The actual file contents are in the "contents" parameter.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!