
File Downloads Done Right - peter123
http://www.therailsway.com/2009/2/22/file-downloads-done-right
======
patio11
I use nginx to serve files, to provide some hotlinking control for my PDFs and
to do split tests on my free trial executables. (I should write about that
some time -- fun, fun stuff, but rather harder than web page split testing.)

To save anyone else doing Rails/nginx some pain, I copy/pasted the important
bits to a pastie. Feel free to use them. In particular note the Content-
Disposition header: if you forget it, you will regret it, particularly if
you're a fan of urls /that/do/not/have/extensions.

<http://pastie.org/396525>

------
jacobian
Anyone using lighttpd might want to check out mod_secdownload
([http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModSecDownloa...](http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModSecDownload))
as an alternative. Nice and lightweight.

------
swombat
I would hope that anyone writing a rails app that involves file downloads
knows this by now....

~~~
mechanical_fish
And how would a beginner know this, unless they are told?

Rails seems to change on a daily basis. Navigating the forest of semi-obsolete
tutorials is a lot of work -- believe me, I know, since I'm coming back to
Rails after some time off, and everything is about 30% different.

People who (a) know what the state of the art is and (b) are willing to
restate it are called "teachers" and they provide an invaluable service.

~~~
FooBarWidget
Then check out <http://guides.rubyonrails.org/> Excellent, high-quality, up-
to-date documentation for almost any Rails topic you can imagine. Even the API
docs have improved leaps and bounds -- yes, send_file is documented as well.

And FYI: send_file has been around since Rails 1.0.0. It's not exactly "state
of the art".

~~~
mechanical_fish
_send_file has been around since Rails 1.0.0_

I'm sure it has. But so have components, and FastCGI, and webrick, and old-
school Test::Unit [1], and fixtures, and the art of constructing CRUD routes
one at a time by hand instead of using map.resources and RESTful routing. And
a lot of other things which are extinct, deprecated, considered harmful,
frowned upon, or generally ignored in favor of newer alternatives.

A blog post doesn't have to contain something new to be informative. Sometimes
the fact that it _doesn't_ contain anything new is informative: It suggests
that the old solution is still considered the canonical solution. [2]

Thanks for the Guides recommendation, by the way. A very useful resource,
indeed.

\--

[1] That is: Test::Unit _without_ Shoulda and/or Rspec enhancement, which seem
to be all the rage these days.

[2] Of course, you have to be confident that the blogger you're reading has
actually been paying attention.

