Forum: Ruby on Rails Deleting files after they are sent via send_file

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Elias O. (Guest)
on 2009-03-26 06:09
(Received via mailing list)
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
Simone R. (Guest)
on 2009-03-26 11:41
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
Elias O. (Guest)
on 2009-03-26 16:01
(Received via mailing list)
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>
This topic is locked and can not be replied to.