my problem is that i can get the save picture to gridFS even if it’s there, i’ve verified and it show me the piture and its name and the size from the console.
here is the code:
conn = Connection()
the classe that saves to the database:
class Profile(tornado.web.RequestHandler):
def post(self):
self.db = conn["essog"]
avat = self.request.files['avatar'][0]["body"]
avctype = self.request.files['avatar'][0]["content_type"]
nomfich = self.request.files['avatar'][0]["filename"]
#..operation using PIL to decide to save the picture or not
self.fs = GridFS(self.db)
avatar_id = self.fs.put(avat, content_type=avctype, filename=nomfich) #change the name later to avoid delete using the same name, so generating a different name...
.....
user={..., "avatar":avatar_id}
self.db.users.insert(user)
self.db.users.save(user)
the class that reads from the database:
class Profil(tornado.web.RequestHandler):
def get(self):
self.db = conn["essog"]
self.fs = GridFS(self.db)
avatar_id = self.db.users.find_one()["avatar"]
...
avatar = self.fs.get(avatar_id).read()
self.render("profile.html",..., avatar=avatar)
and in the view (profile.html)
img src=”{{avatar}}” />
but nothing is displayed!
The
srcattribute of animgtag does not (typically) contain the image data itself, but rather the URL of the image. I think you’re confusing two separate requests and responses:HTML page that contains an
<img src="..." />tag:image itself (which needs a separate handler):