views:

66

answers:

2

Hi all, I am using flask on google app engine and am desperately looking for help to solve this. The GAE documentation talks of storing images in the datastore using the BlobProperty , which should be done something like this:-

class MyPics(db.Model):
      name=db.StringProperty()
      pic=db.BlobProperty()

Now the image should be stored in the datastore by doing this:-

def storeimage():
    pics=MyPics()
    pics.name=request.form['name']
    uploadedpic=request.files['file']  #where file is the fieldname in the form of the                
                                        file uploaded
    pics.pic=db.Blob(uploadedpic)
    pics.put()
    redirect ... etc etc

But am unable to do this. as I get db.Blob accepts a string , but given a Filestorage object... Can someone help me with this. Also if anybody could hint me on how to stream the image back after uploading.

+1  A: 

You should consider using the BlobStore to store your data. Instead of a db.Blob you would be using blobstore.BlobReferenceProperty: http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#BlobReferenceProperty

Uploading and download is quite easy as shown here: http://code.google.com/appengine/docs/python/blobstore/overview.html#Complete_Sample_App

WoLpH
But for blobstore wont I have to activate the payment mechanism. As of now I am just developing, deploying, changing things, working on it etc etc.
Alice
@Alice; Yes, that's true. Enabling billing doesn't automatically cost you money though, the default quotas allow even most small websites to run for free. If enabling payments is an option that that's what I'd suggest.
WoLpH