From 74967f038707374661a6765245c062cb9f7bc7d7 Mon Sep 17 00:00:00 2001
From: leonardovannucci <leonardo.vannucci@digi-one.eu>
Date: Wed, 13 May 2020 15:00:07 +0200
Subject: [PATCH] Fix encoding filename
---
dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java b/dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java
index 1ebd03e..a6ee67f 100644
--- a/dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java
+++ b/dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java
@@ -4,6 +4,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
@@ -33,7 +34,7 @@
@Autowired private RegDocumentRepository regDocumentRepository;
@Autowired private ServletContext servletContext;
- private static final Logger logger = LoggerFactory.getLogger(CloudService.class);
+ private static final Logger logger = LoggerFactory.getLogger(Utils.class);
public URL generateUrl(RegDocument regDocument) throws MalformedURLException {
logger.debug("Genero l'url per il record file {} con id {}", regDocument.getFileName(), regDocument.getDocumentId());
@@ -66,7 +67,7 @@
}
public ResponseEntity<InputStreamResource> getDownloadResponseEntity(String fileName, long id, String secretKey)
- throws FileNotFoundException {
+ throws FileNotFoundException, UnsupportedEncodingException {
logger.debug("Avvio download file {} con id {}", fileName, id);
MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;
@@ -104,7 +105,7 @@
InputStreamResource isr = new InputStreamResource(fis);
return ResponseEntity.ok()
// Content-Disposition
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + file.getName())
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename*=UTF-8''" + java.net.URLEncoder.encode(file.getName(),"UTF-8").replaceAll("\\+", "%20"))
// Content-Type
.contentType(mediaType)
// Contet-Length
--
Gitblit v1.6.2