I am working in a RoR application which allows certain users
to upload files. Currently I store these files
in a directory called “files”. This directory is located in
the RoR application directory:
rails/rails_application/files
So users don’t have access to them.
Now I want users to be able to download some of these files
(they will search based on some parameters). With this
setup I cannot link from my views to that files since they
are out of the public directory.
I could move the files directory to the public directory but
then everybody will have access to those files.
what about a symlink? YOu need some way of getting those files into
the public directory so its a matter of how you want to do it. Bottom
line is they will need to be there at some point.
Maybe on a per request basis copy the original file to the public
directory with some random generated name to make it obscure, and then
delete it.
You want to use an FCGI authorizer, but it is a fairly advanced
technique. The authorizer will ping your app and let you decide
whether to authorize access by returning HTTP 200 to grant access.
The big win is that the files are sent using the web server instead of
routing them through Ruby. lighttpd and apache use the OS implemented
sendfile() which is many times more CPU friendly that sending the file
with Rails. Think of what will happen if 500 users ask for a 100MB
file and they are all using dialup.
Here’s the lighttpd setup, apache supports it too but not webrick.
Thanks to everybody for the replies. They are very helpful.
I will evaluate all the different solutions but I think send_file
is what I was looking for.
Note that ruby send_file ties up your FCGI process until the file is
sent. This will take a long time for a video download or a dialup
user. You may end up needing a lot of simultaneous FCGI processes.
Authorizer ties up the web server for the duration, but not the FCGI
process. The web server is is multithreaded so it can handle being
tied up.
Thanks to everybody for the replies. They are very helpful.
I will evaluate all the different solutions but I think send_file
is what I was looking for.
Note that ruby send_file ties up your FCGI process until the file is
sent. This may take a long time for a video download or a dialup user.
You may end up needing a lot of simultaneous FCGI processes.
Authorizer ties up the web server for the duration, but not the FCGI
process.