Skip to content

Instantly share code, notes, and snippets.

@mikea
Created September 2, 2010 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikea/563022 to your computer and use it in GitHub Desktop.
Save mikea/563022 to your computer and use it in GitHub Desktop.
appengine: upload data to blob programmatically
PAYLOAD_TEMPLATE = \
"""--==boundary\r
Content-Disposition: form-data; name="file"; filename="%s"\r
Content-Type: %s\r
\r
%s\r
--==boundary--\r
"""
destination_url = blobstore.create_upload_url('/upload-sink')
headers = {
'Content-Type': 'multipart/form-data; boundary="==boundary"',
}
image_bytes = open("test_image.jpg", "r").read()
payload = PAYLOAD_TEMPLATE % ('test_image.jpg',
'image/jpeg',
image_bytes)
result = urlfetch.fetch(
destination_url,
method='POST',
headers=headers,
payload=payload,
follow_redirects=False,
deadline=10.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment