Reputation: 1584
Is it possible to upload an image from an external site (i.e. www.example.com/image.png) to the Google App Engine? This is not the same as uploading a file from a user submitted form. If it's possible, any solutions? I'm also using Google Cloud Storage, so if anybody has found a way to accomplish the same thing by uploading straight to Google Cloud Storage, please let me know.
-- UPDATE ---
I've followed the example from here - https://developers.google.com/appengine/docs/python/googlecloudstorageclient/getstarted and replaced the text write "abcd" with this:
url="example.com/image.jpeg"
opener1 = urllib2.build_opener()
page1 = opener1.open(url)
write_retry_params = gcs.RetryParams(backoff_factor=1.1)
gcs_file = gcs.open(filename,
'w',
content_type='image/jpeg',
options={'x-goog-meta-foo': 'foo',
'x-goog-meta-bar': 'bar'},
retry_params=write_retry_params)
gcs_file.write(page1.read())
gcs_file.close()
The problem is - when I run this code, it tries to download the image to my computer (the client) instead of downloading to the gcs_file. I get the download file popup.... That's not what I'm trying to do. What am I doing wrong?
Upvotes: 1
Views: 1235
Reputation: 2276
Yes, you are looking at using the google cloud storage client library. Specifically this: https://developers.google.com/appengine/docs/python/googlecloudstorageclient/functions#open
Open it for writing then write the url fetched image.
Upvotes: 3