SpringCloud Feign请求流文件
Provider
服务提供方接口返回流文件
Consumer
消费者接受方式为fegn.Response,下载:
public ModelAndView getChecklistTree(HttpServletResponse servletResponse) { ModelAndView mv = new ModelAndView(); mv.setView(new DownloadView()); Response response = violationService.download(); Response.Body body = response.body(); Map<String, Collection<String>> headers = response.headers(); InputStream fileInputStream = null; try { fileInputStream = body.asInputStream(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(fileInputStream); } try { String filename = Optional.ofNullable(headers.get("filename11")).map(m -> m.stream().collect(Collectors.toList()).get(0)) .orElse(URLEncoder.encode("分红方案-每股股息.xlsx", "utf-8")); mv.addObject(DownloadView.EXPORT_FILE, fileInputStream); mv.addObject(DownloadView.EXPORT_FILE_NAME, filename); mv.addObject(DownloadView.EXPORT_FILE_TYPE, DownloadView.FILE_TYPE.XLSX); servletResponse.setHeader("fileName", filename); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return mv; }