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
Nithin Reddy wrote:> 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 > > TIANithin -> 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.
> 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 > > enddef 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