Skip to content

Instantly share code, notes, and snippets.

@romanlevin
Last active December 19, 2015 05:08
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 romanlevin/5901664 to your computer and use it in GitHub Desktop.
Save romanlevin/5901664 to your computer and use it in GitHub Desktop.
Python script for uploading an image to a Google App Engine Dev Server's Blobstore from an external URL.
import requests
DEV_SERVER_HOST = 'localhost'
INSTANCE_PORT = 8080
UPLOAD_PATH = 'admin/upload'
def upload_image(url):
def get_upload_url():
cookies = {'dev_appserver_login': 'test@example.com:True'}
resp = requests.get(
'http://%s:%d/%s' % (DEV_SERVER_HOST, INSTANCE_PORT, UPLOAD_PATH),
cookies=cookies)
upload_url = resp.json()['message']
return upload_url
response = requests.get(url)
content_type = response.headers['content-type']
file_extension = content_type.split('/')[1]
image = response.content
files = {'file': ('image.%s' % file_extension, image)}
upload_url = get_upload_url()
response = requests.post(upload_url, files=files)
return response.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment