Basically, my system generates url's to download files from my server. I make this using Struts with a result of type 'stream'. This work great. Now I want to notice for each file downloaded, if it was FULLY downloaded.
I've been searching for a while but really don't know how to continue. I'm a beginner with this.
**
New Action:
**
public String download(){
try {
String path = Init.getWebInfPath() + UploadManager.getInstance().getProperty("UPLOAD_DIR") + content.getZipFile();
file = new FileInputStream(new File(path));
} catch (Exception e) {
return ERROR;
}
Long overallSize = null;
try {
overallSize = file.getChannel().size();
} catch (IOException e) {
e.printStackTrace();
}
response.setContentType("application/zip");
response.addHeader("Content-Disposition", "attachment; filename=\""+content.getZipFile()+"\"");
response.setHeader("Content-Length", String.valueOf(overallSize));
ServletOutputStream sos = null;
try {
sos = response.getOutputStream();
int read;
read = file.read();
while (read>0){
sos.write(read);
read = file.read();
}
} catch(Exception e){
return ERROR;
}
return NONE;
}
**
New xml:
**
<struts>
<package name="content" namespace="/content" extends="default">
<action name="download" class="com.tictapps.adserver.web.content.ContentAction" method="download">
<result name="none"/>
</action>
</package>
</struts>