Forum: Ruby on Rails serving images with send_file performance issue

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5a992f256f765f8ee3dbb2af9d3db4e0?d=identicon&s=25 Robbie Shepherd (robbie)
on 2007-03-13 11:39
I've got an app serving images on the filesystem from outside the
/public directory so I can authenticate users first.

I'm serving the images and thumbnails up using send_file, (1 large 60k
image and 9 6k thumbnails) in one view, and it seems a bit sluggish. Is
this just because of my crappy old windows box running in development
mode - or is each request to serve up an image from an action in the
controller slowing the app down?
F01c3ff32fee35d911e81c172a005012?d=identicon&s=25 Tom Fakes (Guest)
on 2007-03-14 05:50
(Received via mailing list)
Action caching will help improve matters, but if you need to
authenticate for every image, you are already in a bad place for

Lighttpd and I'm sure other servers have a way of serving 'secure'
downloads.  This works by putting a token into the URL for each image
when you generate the HTML.  This token will expire shortly, so only
that user will be able to read those images.  The images are then
served directly by the web server (but only if the token is valid).
I've seen this technique used for downloading purchased MP3 files, and
it worked as advertised.

More info (including a Rails example) at the mod_secdownload page:

On Mar 13, 3:39 am, Robbie Shepherd <>
5a992f256f765f8ee3dbb2af9d3db4e0?d=identicon&s=25 Robbie Shepherd (robbie)
on 2007-03-14 06:18
thanks Tom - after some more research it appears that Mongrel (which I'm
using) seems to be playing a large part in the problem. I read about
using lighttpd and the X-send-file header, which might work better.
F01c3ff32fee35d911e81c172a005012?d=identicon&s=25 Tom Fakes (Guest)
on 2007-03-14 06:28
(Received via mailing list)
I have a plugin that extends Rails Action Caching to use the X-
Sendfile header on lighttpd or the equivalent on nginx to send the
cached file, so your Rails code only needs to care about action
caching, and all the magic will be enabled by the server

More info here:

On Mar 13, 10:18 pm, Robbie Shepherd <rails-mailing-l...@andreas-
9ae68be4f6aff5c6aa7a0eb7087251e9?d=identicon&s=25 PeteSalty (Guest)
on 2007-03-14 08:25
(Received via mailing list)
There's a gem that is supposed to take care of this on Mongrel,
although I haven't tried it. We're about to tackle the same issue so
if you use this and it works for you would you mind dropping us a


On Mar 13, 9:18 pm, Robbie Shepherd <>
This topic is locked and can not be replied to.