4

UPDATE

This question was originally asked at a time when there was no support for programmatic file creation (via url for example). That has changed, see: http://code.google.com/appengine/docs/java/blobstore/overview.html#Writing_Files_to_the_Blobstore

I'm accessing a couple different APIs to fetch images. My application is GAE + Python and I want to use the Blobstore to save these images. The GAE Blobstore documentation provides clear examples of how to save images to Blobstore via a form, but not directly from an url.

http://code.google.com/intl/iw/appengine/docs/python/blobstore/overview.html#Writing_Files_to_the_Blobstore

I want to know how to save http://api.website.com/images/foo.jpg to the Blobstore.

Shedokan
  • 1,212
  • 1
  • 10
  • 21
Will Curran
  • 6,959
  • 15
  • 59
  • 92
  • does anyone know about any alternate solution which is not deprecated for saving images to Blobstore from a link(instead of uploading via form).. GAE Python.. – gsinha Apr 04 '14 at 17:47

3 Answers3

2

HTTP POST to your own form works. I didn't try submitting a file, but here's how I submit a form. You can get the file from the internet, add it to the form submission and the file will store in your blobstore.

import urllib
data = urllib.urlencode({"id":str(id), "password" : self.request.POST['passwd'], "edit" : "edit"})
result = urlfetch.fetch(url="http://www.montao.com.br/upload",
payload=data,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded'})

There's also a similar question answered here

I hope it works for you.

Community
  • 1
  • 1
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
  • 1
    Adding the blobstore context to this. `result = urlfetch.fetch(url=blobstore.create_upload_url('http://www.montao.com.br/upload'),...)` the **blobstore.create_upload_url** provides a "wrapped" url to post into the blobstore which will call your upload handler after blobstore has consumed the posted img with the `blob_info`. – kevpie Dec 31 '10 at 06:28
  • Did you ever get this working? I've used this approach as a model, but am running into problems. http://stackoverflow.com/questions/5370113/how-do-i-save-web-images-to-app-engines-blobstore – Matt Norris Mar 20 '11 at 17:29
2

Using the new File API in combination with urlfetch API you should be able to pass the image url through the form, fetch it server-side and write it to the blobstore:

http://code.google.com/intl/iw/appengine/docs/python/blobstore/overview.html#Writing_Files_to_the_Blobstore

Shedokan
  • 1,212
  • 1
  • 10
  • 21
proppy
  • 10,495
  • 5
  • 37
  • 66
0

You could write an additional handler to upload the content of an input url to the blob store handler. i.e. automating the form submission process. make a POST request to the blob store handler and url encode the image.

But the only problem would be if the file is too large then you might get timeout exceptions.

langerra.com
  • 779
  • 3
  • 8