leonardovannucci
2020-05-13 74967f038707374661a6765245c062cb9f7bc7d7
Fix encoding filename
2 files modified
10 ■■■■■ changed files
dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadFileCaptchaController.java 3 ●●●● patch | view | raw | blame | history
dg1cloud-core/src/main/java/it/digione/dg1cloud/service/Utils.java 7 ●●●●● patch | view | raw | blame | history
dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/DownloadFileCaptchaController.java
....@@ -1,6 +1,7 @@
11 package it.digione.dg1cloud.controller;
22
33 import java.io.FileNotFoundException;
4
+import java.io.UnsupportedEncodingException;
45
56 import javax.validation.Valid;
67
....@@ -28,7 +29,7 @@
2829
2930 @PostMapping
3031 public Object handleDownloadFileCaptcha(@ModelAttribute("downloadFileCaptchaForm") @Valid DownloadFileCaptchaForm form,
31
- BindingResult result) throws FileNotFoundException{
32
+ BindingResult result) throws FileNotFoundException, UnsupportedEncodingException{
3233
3334 ModelAndView modelAndView;
3435 if (result.hasErrors()){
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