Google AppEngine中POST请求中文件的名称

Tho*_*day 3 post google-app-engine

给出html表格......

  <form id="mainform" action="/upload" enctype="multipart/form-data" method="post">
        <div>
            <input type="file" name="img"/>
        </div>
        <div>
            <input type="submit" value="Send">
        </div>
    </form>
Run Code Online (Sandbox Code Playgroud)

......和处理程序......

class Picture(db.Model):
  image = db.BlobProperty()

class Submission(webapp.RequestHandler):
    def post(self):
        picture = Picture()
        image = self.request.get("img")
        picture.image = db.Blob(image)
        picture.put()
        self.redirect('/')
Run Code Online (Sandbox Code Playgroud)

...在处理程序中是否有任何方法可以获取用户为上传输入的文件名?在PHP中,我可以引用$ _FILES ['img'] ['name'],但是我没有看到什么语法(如果有的话)可以用于request.get.在另一个问题中,另一个作者在他的html页面中使用一个javascript例程来提取每次OnChange事件发生时用户选择的文件名,然后在隐藏字段中单独传递它.这有必要吗?PHP似乎免费获取文件名.

Tho*_*day 6

在cgi模块的文档中发现了一个解决方案:

picture.local_filename = self.request.POST[u'img'].filename
Run Code Online (Sandbox Code Playgroud)

请求的POST对象是FieldStorage的集合,而FieldStorage对象具有filename属性.