1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| FeignClient导出 需要返回ResponseEntity<byte[]> ByteArrayOutputStream out = new ByteArrayOutputStream(); XSSFWorkbook workbook = exportCommonExcel(datas,simpleExportBean,null,null,0); workbook.write(out); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentDispositionFormData("attachment", URLEncoder.encode(simpleExportBean.getExportFileName(), "UTF-8")+".xlsx"); httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM); ResponseEntity<byte[]> filebyte = new ResponseEntity<byte[]>(out.toByteArray(), httpHeaders, HttpStatus.OK); return filebyte;
跨服务上传 https://blog.csdn.net/u014534643/article/details/82495648 1. <dependency> <groupId>io.github.openfeign.form</groupId> <artifactId>feign-form</artifactId> <version>3.0.3</version> </dependency> <dependency> <groupId>io.github.openfeign.form</groupId> <artifactId>feign-form-spring</artifactId> <version>3.0.3</version> </dependency> 2. configuration = UpDownFtpFacade.MultipartSupportConfig.class) @RequestPart(value = "file") MultipartFile file, class MultipartSupportConfig {
@FeignClient(value = "**", configuration = UpDownFtpFacade.MultipartSupportConfig.class) public interface UpDownFtpFacade { /** * FTP上传文件 * * @param file 文件 * @param logId 日志id * @return */ @PostMapping(value = "/ftp/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) FtpApiResponse<FtpUploadResDTO> uploadFileFTP(@RequestPart(value = "file") MultipartFile file, @RequestParam("logId") String logId); /** * FTP下载文件 * * @param fileName 文件名 * @param logId 日志id * @return */ @PostMapping(value = "/ftp/downloadFile") FtpApiResponse<String> downloadFileFTP(@RequestParam("fileName") String fileName, @RequestParam("logId") String logId); /** * 引用配置类MultipartSupportConfig.并且实例化 */ @Configuration class MultipartSupportConfig { @Bean public Encoder feignFormEncoder() { return new SpringFormEncoder(); } } }
|