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
May be this will help
@RequestMapping(method = RequestMethod.GET,value = "/getfile")
public @ResponseBody
void getReviewedFile(HttpServletRequest request, HttpServletResponse response, @RequestParam("fileName") String fileName)
{
//do other stuff
byte[] file = //get your file from the location and convert it to bytes
response.reset();
response.setBufferSize(DEFAULT_BUFFER_SIZE);
response.setContentType("image/png"); //or whatever file type you want to send.
try {
response.getOutputStream().write(image);
} catch (IOException e) {
// Do something
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With