I have a REST service code below the code that the file returns, now the problem is in the response body in the PostMan Client. I get a raw response, how can I convert it so that it displays the contents of the file for the client, the goal is to return the file to the user. The file name is "File1.jpeg"
code:
@RequestMapping(value = URIConstansts.GET_FILE, produces = { "application/json" }, method = RequestMethod.GET) public @ResponseBody ResponseEntity getFile(@RequestParam(value="fileName", required=false) String fileName,HttpServletRequest request) throws IOException{ ResponseEntity respEntity = null; byte[] reportBytes = null; File result=new File("/home/arpit/Documents/PCAP/dummyPath/"+fileName); if(result.exists()){ InputStream inputStream = new FileInputStream("/home/arpit/Documents/PCAP/dummyPath/"+fileName); byte[]out=org.apache.commons.io.IOUtils.toByteArray(inputStream); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("content-disposition", "attachment; filename=" + fileName); respEntity = new ResponseEntity(out, responseHeaders,HttpStatus.OK); }else{ respEntity = new ResponseEntity ("File Not Found", HttpStatus.OK); } return respEntity; }
source share