Created
September 2, 2010 21:55
-
-
Save mikea/563022 to your computer and use it in GitHub Desktop.
appengine: upload data to blob programmatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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