I have one image file which i am converting to byte[]
and saving it in database while user click on file link from UI that file has to be downloaded to download i have written one method
public void downloadDeclarationForm(HttpServletRequest request,
HttpServletResponse response) throws IOException {
int payrollId = RequestUtils.getBrowsePayroll(request);
Payroll payroll = itConfigManager.getObjectOrNull(Payroll.class, payrollId);
int year = payrollManager.getYear(payroll.getFromDate());
int id = NumberUtils.toInt(request.getParameter("id"));
try {
byte[] byteBuf = itConfigManager.getDeclarationFormBytes(id, year);
ControllerUtils.writeFileUploadHeaders(response,
itConfigManager.getFileName(id, year), byteBuf.length);
//response.setContentType("image/jpeg");
OutputStream stream = new ByteArrayOutputStream();
response.getOutputStream().write(byteBuf);
response.getOutputStream().flush();
response.getOutputStream().close();
} catch (Exception e) {
e.printStackTrace();
response.getOutputStream().print(
"Error while fetching attachment..");
} finally {
response.getOutputStream().close();
}
}
While i am clicking on the download link it opening the download window even in that window file name is coming correct with correct extension but its not opening the file if i am saving that file to disk and try to open its not opening can any one help me ?