My app has user-specific images that should be accessable like this: http://mydomain.com/user/image/12 (returns a png image) or like this: http://mydomain.com/user/image/12.png (the ".png" gets stripped from the id, returns a png image) I've tried this: - class UserController < ApplicationController - - def image - render_file "#{path_to_png_image_file}" - end - - end but when i run it all that gets rendered is the string "‰PNG" Any ideas? Lindsay _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Try taking a look at the send_data method. http://api.rubyonrails.com/classes/ActionController/Streaming.html#M000044 It looks like it may be what you need. On 8/9/05, Lindsay Bernath <hellolindsay@gmail.com> wrote:> My app has user-specific images that should be accessable like this: > > http://mydomain.com/user/image/12 > (returns a png image) > > or like this: > > http://mydomain.com/user/image/12.png > (the ".png" gets stripped from the id, returns a png image) > > > I've tried this: > > - class UserController < ApplicationController > - > - def image > - render_file "#{path_to_png_image_file}" > - end > - > - end > > but when i run it all that gets rendered is the string "‰PNG" > > Any ideas? > > Lindsay > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- - Aaron 'Jomdom' Ransley - Web: www.jomdom.net - Mail: jomdom@gmail.com _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks Aaron, It does look like what i need - but i can't get it to work. Here's my code: - class UserController < ApplicationController - - def image - send_file "path_to_image.gif", :type => "image/gif", :disposition => "inline" - end - - end When i do this: - http://mydomain.com/user/image I get this: - The image "http://mydomain.com/user/image" cannot be displayed, because it contains errors. And if i change the dispositon to 'attachment' the file i download also has errors. I am sure the original is fine. Anyone know why? Lindsay On 8/10/05, Aaron Ransley <jomdom@gmail.com> wrote:> Try taking a look at the send_data method. > > http://api.rubyonrails.com/classes/ActionController/Streaming.html#M000044 > > It looks like it may be what you need. > > On 8/9/05, Lindsay Bernath <hellolindsay@gmail.com> wrote: > > My app has user-specific images that should be accessable like this: > > > > http://mydomain.com/user/image/12 > > (returns a png image) > > > > or like this: > > > > http://mydomain.com/user/image/12.png > > (the ".png" gets stripped from the id, returns a png image) > > > > > > I've tried this: > > > > - class UserController < ApplicationController > > - > > - def image > > - render_file "#{path_to_png_image_file}" > > - end > > - > > - end > > > > but when i run it all that gets rendered is the string "‰PNG" > > > > Any ideas? > > > > Lindsay > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > -- > - Aaron 'Jomdom' Ransley > - Web: www.jomdom.net > - Mail: jomdom@gmail.com > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Lindsay I was having the same issue as yours; it''s working fine since I set the stream option to false. send_file a_file, :disposition => ''inline'', :stream => false, :type => ''image/gif'' In my case, the file is really small (43 bytes), so setting the stream option to false wont affect performance. This seems to be a known issue: http://dev.rubyonrails.com/ticket/1812 Cloves Carneiro Jr --- Lindsay Bernath <hellolindsay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks Aaron, It does look like what i need - but i > can''t get it to work. > > Here''s my code: > > - class UserController < ApplicationController > - > - def image > - send_file "path_to_image.gif", :type > => "image/gif", > :disposition => "inline" > - end > - > - end > > When i do this: > - http://mydomain.com/user/image > > I get this: > - The image "http://mydomain.com/user/image" cannot > be displayed, > because it contains errors. > > And if i change the dispositon to ''attachment'' the > file i download > also has errors. I am sure the original is fine. > > Anyone know why? > > Lindsay > > > On 8/10/05, Aaron Ransley <jomdom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Try taking a look at the send_data method. > > > > >http://api.rubyonrails.com/classes/ActionController/Streaming.html#M000044> > > > It looks like it may be what you need. > > > > On 8/9/05, Lindsay Bernath > <hellolindsay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > My app has user-specific images that should be > accessable like this: > > > > > > http://mydomain.com/user/image/12 > > > (returns a png image) > > > > > > or like this: > > > > > > http://mydomain.com/user/image/12.png > > > (the ".png" gets stripped from the id, returns a > png image) > > > > > > > > > I''ve tried this: > > > > > > - class UserController < ApplicationController > > > - > > > - def image > > > - render_file > "#{path_to_png_image_file}" > > > - end > > > - > > > - end > > > > > > but when i run it all that gets rendered is the > string "PNG" > > > > > > Any ideas? > > > > > > Lindsay > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > > -- > > - Aaron ''Jomdom'' Ransley > > - Web: www.jomdom.net > > - Mail: jomdom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > > > _______________________________________________ > > 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 >__________________________________________________________ Find your next car at http://autos.yahoo.ca