aspose file tools*
The moose likes Struts and the fly likes Canceling file download?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Canceling file download??" Watch "Canceling file download??" New topic
Author

Canceling file download??

Milan Tomc
Greenhorn

Joined: Mar 06, 2006
Posts: 17
Hi all,

When downloading files I get this well known "open/save/cancel window" to decide what to do.
Everything works fine. Or should I say, wordked fine, until I tried to cancel a download of a bigger file.
If a file is small (say 20 KB) everything is fine.
If a file is 50 KB or more, when I click cancel I get:

IllegalStateException: getOutputStream() has already been called for this response

My question is why?

ps. "done streaming" is only shown with small files before a click on one of the buttons. With bigger files it is shown after I click "Open". It seems that it streams "to a certain limit" and then waits for user input. x()

code below:
-------------------------------------------
in action:
----------

response.setContentLength( (int) info.getFileSize());
setContentType(response, info); //see below

ServletOutputStream outStream = response.getOutputStream();
dao.getFileData(dataId, outStream);
syso("done streaming!")
outStream.flush();

return null;

-----------

private void setContentType(HttpServletResponse resp, FileInfo info) {
...
if (extension.equals("pdf")){
resp.setContentType("application/pdf");
}else if (extension.equals("doc")){
resp.setContentType("application/msword");
}else if (extension.equals("txt")){
resp.setContentType("html/text");
}else if (extension.equals("xls")){
resp.setContentType("application/vnd.ms-excel");
}else{
resp.setContentType("application/x-file-download");
}

resp.setHeader("Content-disposition", "attachment; filename=" + info.getFilename());
resp.setHeader("Cache-Control","cache");
resp.setHeader("Pragma","cache");
resp.setDateHeader ("Expires", (new Date()).getTime()+10000);
}

----------------------

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Canceling file download??