struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roger Varley <roger.var...@googlemail.com>
Subject Re: File Download with multiple files. Design question
Date Sat, 20 Nov 2010 10:20:42 GMT
On Sat, 2010-11-20 at 09:41 +0100, PaweĊ‚ Wielgus wrote:
> Hi All,
> read about streamResult (I assume You use struts2), and also there is
> no need for next action in chain, user can simply check as many files
> as he wants and click download what will call downloadAction that will
> simply return zip file for download, after downoading user is still at
> the same page.
> 
Hi Pawel

That's what I'm doing, but the StreamResult requires an InputStream
which forces the intermediate step of creating a temporary file and it's
the issue of how to clean up the temporary file (knowing when the
StreamResult has completed) that's causing the issue.

Li's suggestion of writing directly to the response.getOutputStream()
would work, but it means my action now has to know about the servlet api
and will be awkward to test.

A third alternative I was considering was something like;

public class DeleteOnCloseFileInputStream extends FileInputStream {

	File file;

	public DeleteOnCloseFileInputStream(File file) {
		super(file);
		this.file = file;
	}
	@Override
	public void close() {
		super.close();
		file.delete();
	}
		
}

and passing that to the StreamResult.

Regards


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


Mime
View raw message