SpringMVC返回檔案流
阿新 • • 發佈:2019-01-27
很方便咯。不多說了@RequestMapping("message/get") @ResponseBody public ResponseEntity<byte[]> getMessageImage(@RequestParam(ImageRequestParam) String fileName) throws IOException { String filePath = FinalString.ImagePath + fileName; File file = new File(filePath); HttpHeaders headers = new HttpHeaders(); headers.setContentDispositionFormData("fileName", EncodeingConverter.convertReturnToISO(fileName)); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); ResponseEntity<byte[]> result = new ResponseEntity<byte[]>(FileUtil.readAsByteArray(file), headers, HttpStatus.OK); return result; }