How to use the Google App Engine Blobstore to save web images

UPDATE

This question was originally asked at a time when there was no support for creating program files (for example, using a URL). This has changed: http://code.google.com/appengine/docs/java/blobstore/overview.html#Writing_Files_to_the_Blobstore

I get access to several image retrieval APIs. My application is GAE + Python, and I want to use Blobstore to save these images. The GAE Blobstore documentation provides clear examples of how to save images to Blobstore through a form, but not directly from a 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 in Blobstore.

+4
source share
3 answers

Using the new file API in combination with the urlfetch API, you can pass the image URL through the form, get it on the server side and write it to blobstore:

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

+2
source

HTTP POST for your own form works. I did not try to submit the file, but here is how I can submit the form. You can get the file from the Internet, add it to the form, and the file will be stored in your blob store.

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'}) 

A similar question was also found there.

I hope this works for you.

+2
source

You can write an additional handler to load the contents of the input URL into the blob storage handler. that is, automate the process of submitting the form. make a POST request to the blob repository handler and url encode the image.

But the problem will only be if the file is too large, then you can get exceptions for the timeout.

0
source

Source: https://habr.com/ru/post/1333812/


All Articles