# Mongrel not serving PDFs (I tried to fix mime-type)

**URL:** <https://www.ruby-forum.com/t/mongrel-not-serving-pdfs-i-tried-to-fix-mime-type/71289>\
**Category:** Rails\
**Created:** [October 6, 2006, 6:46pm UTC](https://www.ruby-forum.com/t/mongrel-not-serving-pdfs-i-tried-to-fix-mime-type/71289 "2006-10-06T18:46:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [October 6, 2006, 6:46pm UTC](https://www.ruby-forum.com/t/mongrel-not-serving-pdfs-i-tried-to-fix-mime-type/71289/1 "2006-10-06T18:46:06Z")

</div>

All,

I’m attempting to GET a PDF file via Mongrel in my development  
environment, and instead of returning a PDF file, I see it rendered as  
text (%PDF-1.5 …etc.) in my browser window.

I was aware that Mongrel has a fairly limited set of mime-types that are  
handled by default, so I went ahead and attempted to add the PDF  
mime-type to the Mongrel handler.rb, like so:

“.pdf” =\> “application/pdf”

After I reboot, I still get the junk and not the PDF. My browser has no  
problems opening PDF files.

What gives? Am I specifying the wrong mime-type?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [October 6, 2006, 7:45pm UTC](https://www.ruby-forum.com/t/mongrel-not-serving-pdfs-i-tried-to-fix-mime-type/71289/2 "2006-10-06T19:45:12Z")

</div>

I put the following in a file “config/mime.types”

.pdf: application/pdf

then I start mongrel with:

mongrel\_rails start -m config/mime.types

ideally, when you switch to a production environment, you’ll have  
apache serving these pdf files directly, but until then, you can use  
the method above.

Mike

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [October 6, 2006, 8:35pm UTC](https://www.ruby-forum.com/t/mongrel-not-serving-pdfs-i-tried-to-fix-mime-type/71289/3 "2006-10-06T20:35:36Z")

</div>

Mike G. wrote:

> I put the following in a file “config/mime.types”
> 
> .pdf: application/pdf
> 
> then I start mongrel with:
> 
> mongrel\_rails start -m config/mime.types
> 
> ideally, when you switch to a production environment, you’ll have  
> apache serving these pdf files directly, but until then, you can use  
> the method above.
> 
> Mike

That seems to work. I’m starting mongrel from within RadRails. Do you  
know:

1. how to tell mongrel to listen on a particular port using the command  
line above?

2. how to pass this -m parameter in RadRails?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [October 6, 2006, 8:43pm UTC](https://www.ruby-forum.com/t/mongrel-not-serving-pdfs-i-tried-to-fix-mime-type/71289/4 "2006-10-06T20:43:03Z")

</div>

I just realized that there is something else I’m not understanding here.  
I am able to successfully serve Word docs from my Mongrel server, but I  
don’t have an entry for the Word mime type in handlers.rb.

How is it that my Word docs. are being transferred correctly to the  
browser when requested from Mongrel? Is that because the browser is  
detecting that the incoming stream is actually a Word doc. (ie. all of  
the MIME type handling is happening on the client)?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [October 6, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/mongrel-not-serving-pdfs-i-tried-to-fix-mime-type/71289/5 "2006-10-06T22:17:06Z")

</div>

On Fri, 6 Oct 2006 20:43:03 +0200  
Wes G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I just realized that there is something else I’m not understanding here.  
> I am able to successfully serve Word docs from my Mongrel server, but I  
> don’t have an entry for the Word mime type in handlers.rb.
> 
> How is it that my Word docs. are being transferred correctly to the  
> browser when requested from Mongrel? Is that because the browser is  
> detecting that the incoming stream is actually a Word doc. (ie. all of  
> the MIME type handling is happening on the client)?

Probably because Microsoft makes sure that all their products work  
together on another plane of existence. You should read about the crap  
IE does so that it works faster with IIS and slower with other servers,  
AND at the TCP/IP level no less.

–  
Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu

> **[Zed A. shaw](https://zedshaw.com/)**
>
> Personal essays and writings by Zed A. Shaw.

[http://mongrel.rubyforge.org/](http://mongrel.rubyforge.org/)  
[http://www.lingr.com/room/3yXhqKbfPy8](http://www.lingr.com/room/3yXhqKbfPy8) – Come get help.

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [October 6, 2006, 10:21pm UTC](https://www.ruby-forum.com/t/mongrel-not-serving-pdfs-i-tried-to-fix-mime-type/71289/6 "2006-10-06T22:21:09Z")

</div>

On Fri, 6 Oct 2006 18:46:06 +0200  
Wes G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> “.pdf” =\> “application/pdf”

Yikes, ok you should really be reading the -h help for start:  
mongrel\_rails start -h

You’ll see an option for -m or --mime PATH. You pass this a YAML file  
that looks like this:

* * *

.jpeg: image/jpeg  
.png: yeah/wateva!

Important point is to you put .jpeg and not jpeg.

After that it should be all good.

> After I reboot, I still get the junk and not the PDF. My browser has no  
> problems opening PDF files.
> 
> What gives? Am I specifying the wrong mime-type?

Most likely, you should borrow your mime types from a server you know  
works with them. Use curl -i to figure out what another server uses.

–  
Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu

> **[Zed A. shaw](https://zedshaw.com/)**
>
> Personal essays and writings by Zed A. Shaw.

[http://mongrel.rubyforge.org/](http://mongrel.rubyforge.org/)  
[http://www.lingr.com/room/3yXhqKbfPy8](http://www.lingr.com/room/3yXhqKbfPy8) – Come get help.
