0
I created a system that uploads several files, but I ran into the following problem: I need to create a way to download according to the element id in the database. I wonder if anyone has an idea I can use to do that job. I created a method in my controller, but it did not work as I wanted.
follows the method I created:
@RequestMapping(value = "/download/{file_name}", method = RequestMethod.GET)
public ModelAndView downloadFile(@PathVariable("fileName") String fileName, HttpServletResponse response){
Path arquivo = Paths.get(fileName + ".pdf");
if(Files.exists(arquivo)){
response.setHeader(" Content-Disposition","attachment, filename=\"" + fileName + ".pdf" + "\"");
response.setContentType(" application/pdf");
try {
Files.copy(arquivo, response.getOutputStream());
response.getOutputStream().flush();
} catch (Exception e) {
e.printStackTrace();
}
}
return new ModelAndView(REQUEST_MAPPING_PAGE_PESQUISAR_ITO);
}
is it mandatory that the return is in byte? , because I have only the file path in the database the image is in a directory inside my web server
– Wesley Santos