学习记录:工具 feign接口调用下载文件

    技术2022-07-10  166

    工具 springCloud feign接口下载文件 public ResponseEntity<byte[]> downFile(String logId) { ResponseEntity<byte[]> result = null; InputStream inputStream = null; DdiTaskLog log = ddiTaskLogService.get(logId); try { // feign文件下载 Response response = fileFeign.uploadFile(AESCodec.encrypt(logId)); Response.Body body = response.body(); inputStream = body.asInputStream(); byte[] b = new byte[inputStream.available()]; inputStream.read(b); HttpHeaders heads = new HttpHeaders(); heads.add(HttpHeaders.CONTENT_DISPOSITION, “attachment;filename=” + log.getFileName()); heads.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE); result = new ResponseEntity<>(b, heads, HttpStatus.OK); } catch (IOException e) { e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; }

    Processed: 0.010, SQL: 9