Servlet Handles the Downloading the Attachment
File attachment = new File(getAttachmentDestDir(reviewCycle), fileName);
if (attachment.exists()) {
response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
response.setHeader("Pragma", "public");
response.setHeader("Cache-control", "must-revalidate");
FileInputStream fileInputStream = new FileInputStream(attachment);
byte[] buffer = new byte[1024];
int byteCount = 0;
ServletOutputStream outputStream = response.getOutputStream();
while ((byteCount = fileInputStream.read(buffer)) >= 0) {
outputStream.write(buffer, 0, byteCount);
}
outputStream.flush();
outputStream.close();
fileInputStream.close();
}
Labels: Java
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home