I''m uploading files via file_column, any suggestions on how to detect the MIME type of a file? I''d rather not do it by a custom file extension parser. It looks like ruby has MIME/Type, but it doesn''t seem to read files. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
i think this should be what you want: # :blabla is assumed to be the name of the form file field. params[:blabla].content_type --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
if the file is being uploaded as part of a form, then you can use the content_type method. If you''re reading the file from disk, you can use the Mime::Types gem from http://mime-types.rubyforge.org/, in which case you''d do something like: content_type = MIME::Types.type_for(''filename_with_extension'').first.content_type Mike On 10/30/06, Thorsten L <duplexxx-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > i think this should be what you want: > > # :blabla is assumed to be the name of the form file field. > params[:blabla].content_type > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What if you don''t have a filename with extension or the extension is unreliable? Is there any lib out there that can accurately detect type (mime type) by looking at the data itself? Thanks for the help. Mike Garey wrote:> if the file is being uploaded as part of a form, then you can use the > content_type method. If you''re reading the file from disk, you can > use the Mime::Types gem from http://mime-types.rubyforge.org/, in > which case you''d do something like: > > content_type = MIME::Types.type_for(''filename_with_extension'').first.content_type > > Mike > > On 10/30/06, Thorsten L <duplexxx-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > i think this should be what you want: > > > > # :blabla is assumed to be the name of the form file field. > > params[:blabla].content_type > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Apparently, no lib can provide the auto detection type. If you''re using linux, use the command ''file'': `file -bi my_file`.strip On 11/14/06, Christopher J. Bottaro <cjbottaro-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > What if you don''t have a filename with extension or the extension is > unreliable? Is there any lib out there that can accurately detect type > (mime type) by looking at the data itself? > > Thanks for the help.--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Bruno Celeste wrote:> Apparently, no lib can provide the auto detection type. If you''re > using linux, use the command ''file'': > > `file -bi my_file`.stripBelatedly... http://shared-mime.rubyforge.org/ looks interesting, has some support for identifying mime-type by ''magic numbers'' -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---