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

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

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

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

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

On Fri, 6 Oct 2006 20:43:03 +0200
Wes G. [email protected] 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


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

On Fri, 6 Oct 2006 18:46:06 +0200
Wes G. [email protected] 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


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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs