| .. | .. |
|---|
| 4 | 4 | import java.io.FileInputStream; |
|---|
| 5 | 5 | import java.io.FileNotFoundException; |
|---|
| 6 | 6 | import java.io.IOException; |
|---|
| 7 | +import java.io.UnsupportedEncodingException; |
|---|
| 7 | 8 | import java.net.MalformedURLException; |
|---|
| 8 | 9 | import java.net.URL; |
|---|
| 9 | 10 | |
|---|
| .. | .. |
|---|
| 33 | 34 | @Autowired private RegDocumentRepository regDocumentRepository; |
|---|
| 34 | 35 | @Autowired private ServletContext servletContext; |
|---|
| 35 | 36 | |
|---|
| 36 | | - private static final Logger logger = LoggerFactory.getLogger(CloudService.class); |
|---|
| 37 | + private static final Logger logger = LoggerFactory.getLogger(Utils.class); |
|---|
| 37 | 38 | |
|---|
| 38 | 39 | public URL generateUrl(RegDocument regDocument) throws MalformedURLException { |
|---|
| 39 | 40 | logger.debug("Genero l'url per il record file {} con id {}", regDocument.getFileName(), regDocument.getDocumentId()); |
|---|
| .. | .. |
|---|
| 66 | 67 | } |
|---|
| 67 | 68 | |
|---|
| 68 | 69 | public ResponseEntity<InputStreamResource> getDownloadResponseEntity(String fileName, long id, String secretKey) |
|---|
| 69 | | - throws FileNotFoundException { |
|---|
| 70 | + throws FileNotFoundException, UnsupportedEncodingException { |
|---|
| 70 | 71 | logger.debug("Avvio download file {} con id {}", fileName, id); |
|---|
| 71 | 72 | |
|---|
| 72 | 73 | MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM; |
|---|
| .. | .. |
|---|
| 104 | 105 | InputStreamResource isr = new InputStreamResource(fis); |
|---|
| 105 | 106 | return ResponseEntity.ok() |
|---|
| 106 | 107 | // 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")) |
|---|
| 108 | 109 | // Content-Type |
|---|
| 109 | 110 | .contentType(mediaType) |
|---|
| 110 | 111 | // Contet-Length |
|---|