Hacker Timesnew | past | comments | ask | show | jobs | submitlogin
File Downloads Done Right (therailsway.com)
36 points by peter123 on Feb 22, 2009 | hide | past | favorite | 10 comments


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


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


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


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.


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".


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.


I went to the site and saw a lot of "yellow" warning icons.

"Guides marked with this icon are currently being worked on. While they might still be useful to you, they may contain incomplete information and even errors."

I don't mean to jerk them off, I think the guides are much better than they were in the past.


Rails seems to change on a daily basis.

Not to worry, though, because almost a quarter of the changes will be mentioned in a blog post. Somewhere. Eventually.

grumble, grumble


I don't think this is a Rails-related issue, as it applies to everyone writing persistent web applications. (Admittedly it is less of an issue if you have non-blocking IO or real threads, but I still use X-SendFile when I have those tools available. The less my app has to do, the better.)


Not just Rails apps. You should do this whether you're using PHP, Python or whatever. The web server is much better at handling static files than the backend app.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: