Is there a way to get the MIME extension of a file_column field? Here's what I want to do (look for comment in before_save method): class ProductFile < ActiveRecord::Base belongs_to :product file_column :file_name def before_save self.file_type = # something that returns the MIME type (e.g. image/jpeg) end end TIA
on 2006-03-03 01:18
on 2006-05-07 05:38
Nithin R. wrote: > self.file_type = # something that returns the MIME type (e.g. image/jpeg) > end > > end > > TIA Nithin -> Did you find a solution for this? I too have a need to get the mime type so that I can subsequently attach the file to an email. I'm also having trouble setting store_dir to a custom setting which will contain a variable reference. (I'm storing ToDo items against a Job - so I want to use the job_id as a collection directory.) TIA, Eric.
on 2006-05-07 11:41
> self.file_type = # something that returns the MIME type (e.g. image/jpeg) > end > > end def before_save self.file_type &&= file_name_state.get_content_type rescue nil end # Also: (params[:my_raw_uploaded_file]).respond_to?(:content_type) #=> true -Kyle