HttpServletResponse response) throws SQLException, IOException {
if (!PermissionUtils.isAuthorized(Permission.READ_ACCESS,orgId,appId)){
return "403";
}
Document document = null;
if (docId != null) {
document = documentService.loadDocument(docId);
}
if (document == null) {
if (orgId != null && appId != null)
return "redirect:/organizations/" + orgId + "/applications/" + appId + "/documents";
else if (orgId != null)
return "redirect:/organizations/" + orgId;
else
return "redirect:/";
}
String contentType = document.getContentType();
response.setContentType(contentType);
if(contentType.equals(documentService.getContentTypeService().getDefaultType())){
response.addHeader("Content-Disposition", "attachment; filename=\""+document.getName()+"."+document.getType()+"\"");
response.setContentType("application/octet-stream");
}
response.addHeader("X-Content-Type-Options", "nosniff");
InputStream in = document.getFile().getBinaryStream();
ServletOutputStream out = response.getOutputStream();
IOUtils.copy(in, out);
in.close();
out.flush();
out.close();