How to use Google App Engine's Blobstore to sa

2019-04-09 10:36发布

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.

3条回答
该账号已被封号
2楼-- · 2019-04-09 11:27

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.

查看更多
三岁会撩人
3楼-- · 2019-04-09 11:27

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.

查看更多
老娘就宠你
4楼-- · 2019-04-09 11:36

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

查看更多
登录 后发表回答