# Accessing content\_type locally

**URL:** <https://www.ruby-forum.com/t/accessing-content-type-locally/64255>\
**Category:** Ruby\
**Created:** [June 23, 2006, 4:28pm UTC](https://www.ruby-forum.com/t/accessing-content-type-locally/64255 "2006-06-23T16:28:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Larrytheliquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/fbc32d/32.png) [@Larrytheliquid](https://www.ruby-forum.com/u/Larrytheliquid)\
**Post date:** [June 23, 2006, 4:28pm UTC](https://www.ruby-forum.com/t/accessing-content-type-locally/64255/1 "2006-06-23T16:28:00Z")

</div>

Hi,

I’m trying to figure out a way to get the same information that you  
would  
from the “content\_type” method of the CGI class.  
The problem is that I want to get this info from a file already in the  
filesystem locally. For example, using ruby’s File.size would give me  
the  
same info as an uploaded CGI object’s size method. However, the file  
class’  
“ftype” method only gives things like “file”, “directory”, etc whereas  
CGI  
“content\_type” (what I want) gives things like “image/png”.

File class: [class File - RDoc Documentation](http://www.ruby-doc.org/core/classes/File.html#M000016)  
CGI class:  
[http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/classes/CGI.html](http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/classes/CGI.html)

---

<div class="post-metadata">

**Author:** ![Larrytheliquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/fbc32d/32.png) [@Larrytheliquid](https://www.ruby-forum.com/u/Larrytheliquid)\
**Post date:** [June 24, 2006, 2:54am UTC](https://www.ruby-forum.com/t/accessing-content-type-locally/64255/2 "2006-06-24T02:54:17Z")

</div>

On Jun 23, 2006, at 10:24 AM, Larrytheliquid wrote:

> “ftype” method only gives things like “file”, “directory”, etc  
> whereas CGI  
> “content\_type” (what I want) gives things like “image/png”.
> 
> File class: [class File - RDoc Documentation](http://www.ruby-doc.org/core/classes/File.html#M000016)  
> CGI class: [http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/classes/](http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/classes/)  
> CGI.html
> 
> –  
> Respectfully:  
> Larry Diehl

I think this is as close are you are going to get: http://raa.ruby-  
[lang.org/project/filemagic/](http://lang.org/project/filemagic/)

You have to remember that MIME types are placed in the headers by the  
web-server.

---

<div class="post-metadata">

**Author:** ![Larrytheliquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/fbc32d/32.png) [@Larrytheliquid](https://www.ruby-forum.com/u/Larrytheliquid)\
**Post date:** [June 27, 2006, 12:00am UTC](https://www.ruby-forum.com/t/accessing-content-type-locally/64255/3 "2006-06-27T00:00:28Z")

</div>

Logan,

Thanks, yeah the problem was that the mime type isn’t part of a file.  
I found MIME::Types [http://rubyforge.org/projects/mime-types/](http://rubyforge.org/projects/mime-types/) and it  
does  
just what I need.

Thanks.
