I''m trying out storing my images in the database and all is well... excepting caching. caches_page :picture def picture @file = File.find( @params.id <http://params.id> ).blob send_data @file, :filename => @file.filename, :type => @file.content_type, :disposition => ''inline'' end - The first hit will load the image from the DB. - The second hit sends the cache, which is stored at (example): ../public/index/picture/33.html The content-type of this file is ''text/html''...so garbage is displayed.. and I can''t figure out where to change this. I don''t want to change a global option, either. Is there a way to avoid the cache being saved with an extention as well? I''ve googled up and down and can''t find a definitive answer. Can you correctly cache images stored in the database? Can someone point me in the right direction? Adam _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Adam Roth <adamjroth-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> I''m trying out storing my images in the database and all is well... > excepting caching....> I''ve googled up and down and can''t find a definitive answer. Can you > correctly cache images stored in the database? Can someone point me in the > right direction?Perhaps this would help: http://scottraymond.net/articles/2005/07/05/caching-images-in-rails Scott Raymond -- redgreenblu.com blinksale.com
Scott, I checked out your page a few hours ago and followed everything pretty closely. That is, everything except the route since I didn''t think adding that would solve the content-type issue. How do you ensure that your gifs/jpgs arent being sent as text/html? Adam On 10/3/05, Scott Raymond <scottraymond-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Adam Roth <adamjroth-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > I''m trying out storing my images in the database and all is well... > > excepting caching. > ... > > I''ve googled up and down and can''t find a definitive answer. Can you > > correctly cache images stored in the database? Can someone point me in > the > > right direction? > > Perhaps this would help: > http://scottraymond.net/articles/2005/07/05/caching-images-in-rails > > Scott Raymond > -- > redgreenblu.com <http://redgreenblu.com> > blinksale.com <http://blinksale.com> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> I checked out your page a few hours ago and followed everything pretty > closely. That is, everything except the route since I didn''t think adding > that would solve the content-type issue. How do you ensure that your > gifs/jpgs arent being sent as text/html?My controller sets the content-type in this line: send_data logo, :filename => ''logo.gif'', :type => ''image/gif'', :disposition => ''inline'' ...which is then cached as 1234.gif, and when the cached version is hit, lighttpd is configured to give the right content-type for the file extension. Scott Raymond -- redgreenblu.com blinksale.com
I''ve been using Imagickmagick/RMagick via Gus van Tulder''s ''ImageMagick for rails'' gem: http://vantulder.net/rails/magick/ It caches images wonderfully. I''m not pulling images out of a db with it however, but I think others on this list are. Do a search for ''ImageMagick'' here. HTH On Oct 3, 2005, at 6:07 PM, Scott Raymond wrote:>> I checked out your page a few hours ago and followed everything >> pretty >> closely. That is, everything except the route since I didn''t think >> adding >> that would solve the content-type issue. How do you ensure that your >> gifs/jpgs arent being sent as text/html? >> > > My controller sets the content-type in this line: > > send_data logo, :filename => ''logo.gif'', :type => ''image/gif'', > :disposition => ''inline'' > > ...which is then cached as 1234.gif, and when the cached version is > hit, lighttpd is configured to give the right content-type for the > file extension. > > Scott Raymond > -- > redgreenblu.com > blinksale.com > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 3.10.2005, at 22.59, Adam Roth wrote:> I''m trying out storing my images in the database and all is well... > excepting caching. > > caches_page :picture > > def picture > @file = File.find( @params.id ).blob > send_data @file, :filename => @ file.filename, > :type => @file.content_type, > :disposition => ''inline'' > end > > > - The first hit will load the image from the DB. > - The second hit sends the cache, which is stored at (example): > > ../public/index/picture/33.html > > The content-type of this file is ''text/html''...so garbage is > displayed.. and I can''t figure out where to change this. I don''t > want to change a global option, either. Is there a way to avoid the > cache being saved with an extention as well? > > I''ve googled up and down and can''t find a definitive answer. Can > you correctly cache images stored in the database? Can someone > point me in the right direction?Adam, I think the only way at this point is to use routing to use the correct file suffix: map.connect '':controller/image/:id/pic.jpg'', :action => ''image'' This way the file will be stored with the correct suffix. You can also set the content-type header in the image action but I don''t think it matters in this case since rails is not at all involved in serving stuff from the page cache. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails