Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is some code I tested locally that should do the trick (I used a different handler than webapp2 but tried to modify it to webapp2. You'll also need the poster lib found here <a href="http://atlee.ca/software/poster/" rel="noreferrer">http://atlee.ca/software/poster/</a>):</p> <p>In your POST handler on GAE:</p> <pre><code>from google.appengine.api import urlfetch from poster.encode import multipart_encode payload = {} payload['test_file'] = self.request.POST['test_file'] payload['user_id'] = self.request.POST['user_id'] to_post = multipart_encode(payload) send_url = "http://127.0.0.1:8000/" result = urlfetch.fetch(url=send_url, payload="".join(to_post[0]), method=urlfetch.POST, headers=to_post[1]) logging.info(result.content) </code></pre> <p>Make sure your HTML form contains <code>method="POST" enctype="multipart/form-data"</code>. Hope this helps!</p> <p><strong>EDIT:</strong> I tried using the webapp2 handler and realized the way files are served are different than how the framework I used to test with works (KAY). Here is updated code that should do the trick (tested on production):</p> <pre><code>import webapp2 from google.appengine.api import urlfetch from poster.encode import multipart_encode, MultipartParam class UploadTest(webapp2.RequestHandler): def post(self): payload = {} file_data = self.request.POST['test_file'] payload['test_file'] = MultipartParam('test_file', filename=file_data.filename, filetype=file_data.type, fileobj=file_data.file) payload['name'] = self.request.POST['name'] data,headers= multipart_encode(payload) send_url = "http://127.0.0.1:8000/" t = urlfetch.fetch(url=send_url, payload="".join(data), method=urlfetch.POST, headers=headers) self.response.headers['Content-Type'] = 'text/plain' self.response.out.write(t.content) def get(self): self.response.out.write(""" &lt;html&gt; &lt;head&gt; &lt;title&gt;File Upload Test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="" method="POST" enctype="multipart/form-data"&gt; &lt;input type="text" name="name" /&gt; &lt;input type="file" name="test_file" /&gt; &lt;input type="submit" value="Submit" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;""") </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload