# How to get mime extension with file\_column

**URL:** <https://www.ruby-forum.com/t/how-to-get-mime-extension-with-file-column/76034>\
**Category:** Rails\
**Created:** [March 3, 2006, 12:18am UTC](https://www.ruby-forum.com/t/how-to-get-mime-extension-with-file-column/76034 "2006-03-03T00:18:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jashugan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bcef8e/32.png) [@jashugan](https://www.ruby-forum.com/u/jashugan)\
**Post date:** [March 3, 2006, 12:18am UTC](https://www.ruby-forum.com/t/how-to-get-mime-extension-with-file-column/76034/1 "2006-03-03T00:18:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jashugan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bcef8e/32.png) [@jashugan](https://www.ruby-forum.com/u/jashugan)\
**Post date:** [May 7, 2006, 3:38am UTC](https://www.ruby-forum.com/t/how-to-get-mime-extension-with-file-column/76034/2 "2006-05-07T03:38:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jashugan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bcef8e/32.png) [@jashugan](https://www.ruby-forum.com/u/jashugan)\
**Post date:** [May 7, 2006, 9:41am UTC](https://www.ruby-forum.com/t/how-to-get-mime-extension-with-file-column/76034/3 "2006-05-07T09:41:10Z")

</div>

> ```
> 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
