Eng Mohamed Ramzy Eng Mohamed Ramzy - 10 months ago 38
Python Question

How to upload images and storing it in db google app engine

Hello i want to know how to upload a picture from the user and store it in data base using this form ( using google data store)

<form method='post'>
<input type='file' name='img'>
<input type='submit'>

i have made a db model

from google.appengine.ext import db
class Photo(db.model):
profile_pic = db.BlobProperty()

and when i display it in the web app the name only appears

ex : example.png

i want to know how to upload it using

from google.appengine.ext import db


from google.appengine.ext import ndb


You can use the blobstore and a BlobReferenceProperty.

class Image(db.Model): 
    primary_image = blobstore.BlobReferenceProperty()

Then you have an upload handler where you can add image using http post:

class UploadHandler(BaseRequestHandler,
   def post(self):

        for upload in self.get_uploads():
                img = Image()
                img.primary_image = upload.key()