File management!

Hi, I’m new to ROR. I was wondering how to:

  1. Check if the file is being read/downloaded/…
  2. Rename files

If you can help or point out any document that I need to read to
accomplish this, please do. Thanks a lot.

vu nguyen wrote:

Hi, I’m new to ROR. I was wondering how to:

  1. Check if the file is being read/downloaded/…
    By (possibly) another process? Via the webserver? You’ll have to add
    that manually, I think.
  1. Rename files
    File.rename(‘oldfilename’, ‘newfilename’)

If you can help or point out any document that I need to read to
accomplish this, please do. Thanks a lot.

http://www.ruby-doc.org/core/classes/File.html

Wow, thanks a lot. The reason I asked was that I want to allow users
download files from my host, yet hide the real url from them to prevent
leaching.

The solution I came up with was: let the user download the file, check
if the files downloaded (not being read), then rename it. Of course the
database will keep track of the files for me.
But today I did some check and found out some thing interesting: even if
I change the file name while the user downloading it, it wouldnt affect
their current download → Then I dont have to check if the file is
being accessed (which is a hard job to do)

Also I found another interesting solution:
http://www.webclass.ru/eng/Tutorials/Perl/How_to_hide.html
Basically instead of sending the file header to the user’s browser, you
print out the file content. I wonder if it’s possible to do on Rails
tho, and what happen if the file is pretty big and not an image file…

vu nguyen wrote:

being accessed (which is a hard job to do)
If the file’s popular, there’s a race condition in there:

Client X sees the page, notes the filename as ‘aaa.zip’.
Client Y sees the page, notes the filename as ‘aaa.zip’.
Client X requests the file as ‘aaa.zip’.
Server renames the file to ‘bbb.zip’.
Client Y requests the file as ‘aaa.zip’.
Client Y gets a 404.

Slight snag.

Huhm, this is mailing list so I cant edit what I posted _. Anyway,
just to add 1 thing: after sending the header to the browser/Dmanager so
the download can start, I will just rename my file/or the parent
folder.(which does not affect the current downloads in any way).

Alex Y. wrote:

vu nguyen wrote:

being accessed (which is a hard job to do)
If the file’s popular, there’s a race condition in there:

Client X sees the page, notes the filename as ‘aaa.zip’.
Client Y sees the page, notes the filename as ‘aaa.zip’.
Client X requests the file as ‘aaa.zip’.
Server renames the file to ‘bbb.zip’.
Client Y requests the file as ‘aaa.zip’.
Client Y gets a 404.

Slight snag.

Interesting, but then you have to rename it back after some time? Or you
keep track using database?

Talking about link hiding, I used readfile() when I worked with PHP
(still do). But now I think of a better way: give each file 1 unique id,
keep track in mysql. Everytime the browser/download manager requests the
file, I simply send back the header to that file. That way my users can
use RESUME.
I can still authenticate and prevent leaching, and my users can resume
their broken download files.