Deleting files after they are sent via send_file


#1

Hello guys,

I am having the option to download certain folders on my app in zip
format. So every time a user requests one I’m doing a system call to
zip the folder (ex: system('cd ‘+path+’ && zip …) and then the
send_file method to send it.

What happens is that I’m keeping track of disk space so I need to
delete the zip immediately. I was wondering if there is a way of
creating the zip file in a sort of tmp directory and send it via
send_file from the tmp path. I don’t know when the file transfer is
over to delete the zip file and having a cron job to delete zip files
is not an option (disk space could be surpassed by the zip file and
the user will have to wait for it to be deleted to be able to create
new files). Can anyone point me in the right direction please. Thanks,

Elías


#2

Elias O. wrote:

Hello guys,

I am having the option to download certain folders on my app in zip
format. So every time a user requests one I’m doing a system call to
zip the folder (ex: system('cd ‘+path+’ && zip …) and then the
send_file method to send it.

What happens is that I’m keeping track of disk space so I need to
delete the zip immediately. I was wondering if there is a way of
creating the zip file in a sort of tmp directory and send it via
send_file from the tmp path. I don’t know when the file transfer is
over to delete the zip file and having a cron job to delete zip files
is not an option (disk space could be surpassed by the zip file and
the user will have to wait for it to be deleted to be able to create
new files). Can anyone point me in the right direction please. Thanks,

El�as

I dont’know how to do it in RoR (i’m a newbie) but wen i was using the
old ASP there was an “onSessionEnd” where you can script some task to do
when a session end (both for logout or timeout)

You can just bind the zip to a session and when the session end you can
delete the file


#3

I have been doing some research and only found about using cron jobs
to do the cleaning (a point I discussed on my initial message) and
also found this:

There is an send_file option:
:stream - whether to send the file to the user agent as it is read
(true) or to read the entire file before sending (false). Defaults to
true. When U set :stream => false U can delete the file just after
send_file return.

I wonder if someone has used this before and if there is any
disadvantage to this approach.

Thanks again,

Elías

On Mar 26, 4:41 am, “Simone R.” removed_email_address@domain.invalid