Google AppEngine Python Web Upload File And Read The Content
I'm new at Python AND AppEngine, so maybe my question is basic but I've searched it for hours... So, I'm using Google AppEngine with python and HTML... So in my htlm file I have
Solution 1:
You can use cgi.FieldStorage() to upload a file < 32 megabytes. But you have to send the form as enctype="multipart/form-data"
<form action="/upload" enctype="multipart/form-data" method="post">
<div><input type="file" name="file"/></div>
<div><input type="submit" value="Upload"></div>
</form>
The post method in the /upload
webapp2 request handler:
def post(self):
field_storage = self.request.POST.get("file", None)
if isinstance(field_storage, cgi.FieldStorage):
file_name = field_storage.filename
file_data = field_storage.file.read())
.....
else:
logging.error('Upload failed')
Example taken from this gist
Solution 2:
Try this:
fileitem = self.request.POST['file']
If you want to store the file I would look into uploading it straight to Blob store first then process it as needed.
https://developers.google.com/appengine/docs/python/blobstore/
Post a Comment for "Google AppEngine Python Web Upload File And Read The Content"