The file name in the POST request in Google AppEngine

Given the shape of 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>

... and a handler ...

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('/')

... is there any way inside the handler to get the file name entered by the user to download? In PHP, I can refer to $ _FILES ['img'] ['name'], but I don’t see which syntax, if any, will work with request.get. In another question, another author uses the javascript routine on his html page to extract the file name that the user selects each time the OnChange event occurs, and then pass it separately to the hidden field. It's necessary? PHP seems to get the file name for free.

+3
source share
1 answer

cgi:

picture.local_filename = self.request.POST[u'img'].filename

POST - FieldStorage, FieldStorage .

+6

Source: https://habr.com/ru/post/1699193/


All Articles