download filename
This commit is contained in:
parent
236e3b4047
commit
93f951ca22
@ -3,6 +3,7 @@ package com.manalejandro.arjion.controllers;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@ -130,7 +131,7 @@ public class MainController {
|
||||
ByteArrayResource resource = new ByteArrayResource(Files.readAllBytes(path));
|
||||
String type = file.toURL().openConnection().guessContentTypeFromName(filename);
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.add("content-disposition", "attachment; filename=" + filename);
|
||||
responseHeaders.add("Content-Disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));
|
||||
responseHeaders.add("Content-Type", type);
|
||||
return ResponseEntity.ok().contentLength(file.length()).headers(responseHeaders)
|
||||
.contentType(MediaType.parseMediaType("application/octet-stream")).body(resource);
|
||||
|
Loading…
Reference in New Issue
Block a user