deciphertools.com

How to Handle Direct File Upload Google App Engine Python

Tap here to send yourself this article and receive a 10% coupon code!

I searched my little heart out on the query "Python Direct File Upload Google App Engine" until I had given up hope thinking it was only doable in PHP. I finally stumbled on this blog post explaining how to handle uploads in webapp2 in python.

Here's how to handle direct file uploads in Google App Engine Python:

Step 1. Make sure your form tag includes enctype="multipart/form-data".

  <form action="yourHandlerUrl" class="form" method="POST" enctype="multipart/form-data">

Step 2. Add your file selector to your form.

      <input type="file" name="yourFileName" >

Step 3. In your form handler, instead of using self.request.get which will give you the file's name, use self.request.POST.get which will return a StringIO object.

fileObj = self.request.POST.get("yourFileName")

Step 4. Do what you need with it, such as iterate through the lines of the file:

for line in fileObj.file:
    #do cool stuff with line
    logging.info(line)

Remember that there is a 32MB size limit on direct upload files.

Write A Comment

Decipher Tools Home

San Francisco / Phoenix, USA

© 2024 Decipher Media, LLC. · Privacy