Hi, I''m using file_column to save images to the file system. To protect the images, I''m uploading to a non-publicly accessible directory. Therefore, I''m using a controller method to send the file when requested: def get_pic @fctrial = Fctrial.find(params[:id]) send_file(@fctrial.image, {:disposition => ''inline'', :type => ''image/jpeg''}) end As you can see, I''m setting the :type to ''image/jpeg'' so obviously this is not correct for image/png or image/gif. How do I get to send the correct content type? Should I save the content type in the database also? Is there some simpler way? Thanks, Mohit. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
You could inspect the filename and use that to figure out what type of file. Like: type = ''image/gif'' if @fctrial[''image''] =~ /gif$/ (I don''t know if the regex is correct) On 9/2/06, Mohit Sindhwani <mo_mail-RxrYI66vbj0AvxtiuMwx3w@public.gmane.org> wrote:> > > Hi, I''m using file_column to save images to the file system. To protect > the images, I''m uploading to a non-publicly accessible directory. > Therefore, I''m using a controller method to send the file when requested: > > def get_pic > @fctrial = Fctrial.find(params[:id]) > send_file(@fctrial.image, {:disposition => ''inline'', :type => > ''image/jpeg''}) > end > > > As you can see, I''m setting the :type to ''image/jpeg'' so obviously this > is not correct for image/png or image/gif. How do I get to send the > correct content type? Should I save the content type in the database > also? Is there some simpler way? > > Thanks, > Mohit. > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Mohit Sindhwani
2006-Sep-03 15:55 UTC
Re: Using file_column and sending correct content type
Greg Gross wrote:> You could inspect the filename and use that to figure out what type of > file. > > Like: > > type = ''image/gif'' if @fctrial[''image''] =~ /gif$/ > (I don''t know if the regex is correct)Thanks, Greg! That should work.. I was just wondering if file_column stored that information somewhere.. cos, obviously, it knows when the file is uploaded! :D Cheers Mohit. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---