I had uploaded images to mongoDB using GridFS. I want to retrieve an image from the db and display it in the browser. How to do this with the help of Sinatra and HAML.
+1
A:
This Sinatra app uses the old GridStore API, but the principle still applies. Create a separate URL for images, set the content type, and call #read on the Grid method:
http://github.com/banker/mongodb_examples/blob/master/tweets/sinatra_tweets.rb
Kyle Banker
2010-04-12 14:22:47
Actually I'm using GridFileSystem, since GridStore API is deprecated. In GridFileSystem, when I say, read, some byte codes are getting displayed in the browser. How to make the image to appear on the browser?
Prakash
2010-04-15 05:34:43
It doesn't matter which API you're using. You need to serve the image with the proper content type. Note how that's done in the example just provided. Note also how I display the image in my html: http://github.com/banker/mongodb_examples/blob/master/tweets/views/tweets.erb
Kyle Banker
2010-04-17 17:58:36
This is exactly what I was looking for. Setting the content-type fixed everything for me - thanks!
funkymunky
2010-05-19 03:31:00