Get original filename google app engine

2019-02-24 04:48发布

When receiving a file upload on google app engine, the example assumes you're receiving a .png. However you only konw what the type of the image is by the extension on the filename.

How do you get the original filename uploaded on GAE?

2条回答
The star\"
2楼-- · 2019-02-24 05:47

The filename of the file that is being uploaded can be determined by looking at the filename property of the variable that holds the file. For example, let's say that your form has a field named content:

<input type="file" name="content" />

Inside your Handler, you could find the name of the file with:

filename = self.request.POST["content"].filename
查看更多
乱世女痞
3楼-- · 2019-02-24 05:47

It seems that the newly introduced BlobStore has direct support for original filename in the blob's properties. http://code.google.com/appengine/docs/python/blobstore/blobinfoclass.html#BlobInfo_filename

You will need to register a credit card with App Engine to be able to use the BlobStore in production though, even if you don't plan on exceeding the free quotas.

查看更多
登录 后发表回答