Forum: Ruby on Rails How to get mime extension with file_column

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Nithin R. (Guest)
on 2006-03-03 01:18
(Received via mailing list)
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
Eric S. (Guest)
on 2006-05-07 05:38
(Received via mailing list)
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.
Kyle M. (Guest)
on 2006-05-07 11:41
(Received via mailing list)
>     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
This topic is locked and can not be replied to.