leonardovannucci
2020-05-13 74967f038707374661a6765245c062cb9f7bc7d7
dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java
....@@ -4,6 +4,7 @@
44 import java.io.FileInputStream;
55 import java.io.FileNotFoundException;
66 import java.io.IOException;
7
+import java.io.UnsupportedEncodingException;
78 import java.net.MalformedURLException;
89 import java.net.URL;
910
....@@ -33,7 +34,7 @@
3334 @Autowired private RegDocumentRepository regDocumentRepository;
3435 @Autowired private ServletContext servletContext;
3536
36
- private static final Logger logger = LoggerFactory.getLogger(CloudService.class);
37
+ private static final Logger logger = LoggerFactory.getLogger(Utils.class);
3738
3839 public URL generateUrl(RegDocument regDocument) throws MalformedURLException {
3940 logger.debug("Genero l'url per il record file {} con id {}", regDocument.getFileName(), regDocument.getDocumentId());
....@@ -66,7 +67,7 @@
6667 }
6768
6869 public ResponseEntity<InputStreamResource> getDownloadResponseEntity(String fileName, long id, String secretKey)
69
- throws FileNotFoundException {
70
+ throws FileNotFoundException, UnsupportedEncodingException {
7071 logger.debug("Avvio download file {} con id {}", fileName, id);
7172
7273 MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;
....@@ -104,7 +105,7 @@
104105 InputStreamResource isr = new InputStreamResource(fis);
105106 return ResponseEntity.ok()
106107 // Content-Disposition
107
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + file.getName())
108
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename*=UTF-8''" + java.net.URLEncoder.encode(file.getName(),"UTF-8").replaceAll("\\+", "%20"))
108109 // Content-Type
109110 .contentType(mediaType)
110111 // Contet-Length