Scribble instead of memo for business. I will make a decent article later.
Finally, just return the Resouce type file from Controller If you want to download a local file
AnyController.java
Resource resource = new FileSystemResource("File path here");
return resource;
Added HttpServeletResponse response to Controller argument. Set an appropriate value in the field variable (header) of response. You can leave the return etc. as it is. The Spring side will take care of it.
AnyController.java
//Argument description omitted
Resource resource = new FileSystemResource("File path here");
response.setHeader("Content-Disposition", "attachment; filename=" + "File name here");
return resource;
It's OK if the file name is URL-encoded
AnyController.java
//Argument description omitted
Resource resource = new FileSystemResource("File path here");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("File name here", "UTF-8"));
return resource;
Recommended Posts