Fix critical issue with file exports on chromium based web browsers

This commit is contained in:
George Kalampokis 2021-11-02 14:50:20 +02:00
parent e46de79ec2
commit 39795f177f
6 changed files with 13 additions and 8 deletions

View File

@ -185,7 +185,7 @@ public class DMPs extends BaseController {
ResponseEntity<byte[]> getPDFDocument(@PathVariable String id, @RequestHeader("Content-Type") String contentType,
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
FileEnvelope file = this.dataManagementPlanManager.getWordDocument(id, principal, configLoader);
String name = file.getFilename().substring(0, file.getFilename().length() - 5);
String name = file.getFilename().substring(0, file.getFilename().length() - 5).replace(" ", "_").replace(",", "_");
File pdffile = PDFUtils.convertToPDF(file, environment);
InputStream resource = new FileInputStream(pdffile);
logger.info("Mime Type of " + name + " is " +

View File

@ -135,7 +135,8 @@ public class Datasets extends BaseController {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(file.getFile().length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getFilename());
String fileName = file.getFilename().replace(" ", "_").replace(",", "_");
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName);
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
@ -218,7 +219,7 @@ public class Datasets extends BaseController {
public @ResponseBody
ResponseEntity<byte[]> getPDFDocument(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
FileEnvelope file = datasetManager.getWordDocumentFile(this.configLoader, id, this.getApiContext().getUtilitiesService().getVisibilityRuleService(), principal);
String fileName = file.getFilename();
String fileName = file.getFilename().replace(" ", "_").replace(",", "_");
if (fileName.endsWith(".docx")){
fileName = fileName.substring(0, fileName.length() - 5);
}

View File

@ -1475,7 +1475,7 @@ public class DataManagementPlanManager {
/*ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);*/
String fileName = "DMP_" + dmp.getGrant().getLabel() + "_" + dmp.getVersion();//dmp.getLabel();
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "").replace(" ", "_").replace(",", "_");
String uuid = UUID.randomUUID().toString();
File file = new File(this.environment.getProperty("temp.temp") + uuid + ".json");
OutputStream output = new FileOutputStream(file);
@ -1514,11 +1514,12 @@ public class DataManagementPlanManager {
default:
file = getXmlDocument(id, principal);
}
String fileName = file.getFilename().replace(" ", "_").replace(",", "_");
InputStream resource = new FileInputStream(file.getFile());
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(file.getFile().length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getFilename());
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName);
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");

View File

@ -104,7 +104,8 @@ public class DataManagementProfileManager {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(envelope.getFile().length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + envelope.getFilename() + ".xml");
String fileName = envelope.getFilename().replace(" ", "_").replace(",", "_");
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName + ".xml");
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource);

View File

@ -853,7 +853,8 @@ public class DatasetManager {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(envelope.getFile().length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + envelope.getFilename() + ".xml");
String fileName = envelope.getFilename().replace(" ", "_").replace(",", "_");
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName + ".xml");
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");

View File

@ -208,7 +208,8 @@ public class DatasetProfileManager {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(envelope.getFile().length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + envelope.getFilename() + ".xml");
String fileName = envelope.getFilename().replace(" ", "_").replace(",", "_");
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName + ".xml");
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");