user664546
user664546

Reputation: 5041

appengine save image to blobstore from url

Im trying to upload an image to the blobstore and return the serving url, this is where im at so far:

url ='http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=b25b959554ed76058ac220b7b2e0a026&artist=blink-182&track=dammit&format=json'
result = urlfetch.fetch(url=url, deadline=10, method=urlfetch.GET,).content

    if result:
        data = json.loads(result)
        imageUrl = data['track']['album']['image'][3]['#text']


        result = urlfetch.fetch(imageUrl)
        if result.status_code == 200:
            image_result = db.Blob(result.content)

I need to return the blobs serving url so I can save it with another entity.

any help is appreciated

thanks J

Upvotes: 1

Views: 1818

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 600049

You've confused two things.

A db.Blob is the type of a blob stored within a model. It doesn't have a "serving URL". If you want to serve one, you need to write view code to load the model instance it's stored in from the datastore, and return the blob data directly.

If you want to store blobs and serve them independently of datastore models, you need to use the (experimental) blobstore API.

The documentation has a good writeup on how to write files to the blobstore programatically. You can then pass that to the images API to get a URL:

from google.appengine.api import images
url = images.get_serving_url(blob_key)

Upvotes: 2

Related Questions