You'll need to explain protect but still allow access.
You could store them in another directory and then use send_file to
send the file after some form of authentication.
You can also do this with nginx (better scalability) via the method I
explain on my blog at
http://ramblingsonrails.com/how-to-protect-downloads-but-still-have-nginx-serve-the-files
A similar method exists for Apache.
by "still allow access" I simply meant that I could still refer to the
images in my HTML. ( <img src='/images/pic.jpg'> )
send_file isn't appropriate here ( as far as I'm aware ).
Suppose my profile image is located at "images/3.jpg". I want to
prevent users from then visiting "images/4.jpg" and checking out
pictures they don't have access to.
So far, encypting the image name seems to be the only solution.
ie- "images/8dfa7dg6g82h9dhn9njn23knjkknsdf9.jpg"
Making it a little more difficult to 'guess' the picture url.
send_file isn't appropriate here ( as far as I'm aware ).
Why not? It sounds like exactly what you want -- a way to send an
arbitrary file that isn't in the public directory.
Suppose my profile image is located at "images/3.jpg". I want to
prevent users from then visiting "images/4.jpg" and checking out
pictures they don't have access to.
Then don't put the images in the public directory. The public directory
is, well, public.
So far, encypting the image name seems to be the only solution.
ie- "images/8dfa7dg6g82h9dhn9njn23knjkknsdf9.jpg"
Making it a little more difficult to 'guess' the picture url.
Why not? It sounds like exactly what you want -- a way to send an
arbitrary file that isn't in the public directory.
Isn't send_file for streaming the file to the user though?
I'm only looking to load the image on screen, I don't want the users
to actually download a copy of the file.
Was not aware of that.
I think in this case it's best to go with the encrpted filename
option because I'll might have loads of images to render per page.
:x_sendfile - uses X-Sendfile to send the file when set to true. This
is currently only available with Lighttpd/Apache2 and specific modules
installed and activated. Since this uses the web server to send the
file, this may lower memory consumption on your server and it will not
block your application for further requests. See
X-Sendfile - lighty's life and
tn123.ath.cx is offline for details. Defaults to false.