Return a file from Controller in Spring
spring, spring-mvc
Solution
Thanks to @JAR.JAR.beans. Here is the link: Downloading a file from spring controllers
@RequestMapping(value = "/files/{file_name}", method = RequestMethod.GET)
@ResponseBody
public FileSystemResource getFile(@PathVariable("file_name") String fileName) {
return new FileSystemResource(myService.getFileFor(fileName));
}
Problem
I am new to spring. I have a controller with a RequestMapping for several GET parameters. They return a String . But one method needs to return a file in the "/res/" folder. How do I do that? ``` @RequestMapping(method = RequestMethod.GET,value = "/getfile") public @ResponseBody String getReviewedFile(@RequestParam("fileName") String fileName) { return //the File Content or better the file itself } ``` Thanks