struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Li Ying <liying.cn.2...@gmail.com>
Subject Re: File Download with multiple files. Design question
Date Fri, 19 Nov 2010 14:26:43 GMT
My suggestion:

(1)I believe you can use ZipOutputStream to output the zipped data to
the response OutputStream directly, instead of a temp file. So no temp
file need to be created.

OR

(2)You can create a batch application, repeatedly run it with some
interval (use cron or something).
And in this batch app, you can check the timestamp of your temp files,
and delete them if they are old enough.

I think the first way is the best, because there is not any side effects.
But the second way is also valuable, because it can help you to clean
up your working folder when you really need temp files.



2010/11/19 RogerV <roger.varley@googlemail.com>:
>
> Hi
>
> I have a requirement to present the user with a list of files stored on the
> server, and then download the files selected to the user. If the user
> selects a single file - no problem. However if the user selects multiple
> files, then, unless anyone knows different, all the files have to be sent in
> the single input stream read by the stream result. Therefore I create a
> temporary file with File.createTempFile() and use the ZipOutputStream to zip
> the files and then return an input stream over the temp file. This works
> suprisingly well. However, the problem I've now got is, how to get rid of
> the temp files I am creating on the server?
>
> file.deleteOnExit() is no use because the server VM will (in theory) never
> shutdown. Once the download is complete Struts automatically re-displays the
> original selection screen and provided the user uses the applicatoin
> supplied navigation to exit then I can delete the temp file, but if they
> simply close the browser or use the browser back button to navigate away I'm
> still left with the temp files sitting around.
>
> Creating the zipfile in memory is not an option as some of these can
> potentially be huge if the user goes mad and selects everything in sight.
>
> Is there someway of detecting/intercepting the fact that the Stream result
> has completed before Struts gets on with deciding what .jsp to display next
> so that I can safely clean up? Any other suggested approaches would be
> welome.
>
> Regards
>
> --
> View this message in context: http://old.nabble.com/File-Download-with-multiple-files.-Design-question-tp30256036p30256036.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message