Spring通过FeignClient调用文件上传服务上传本地磁盘文件代码如下:
//2. 图片解码并保存
String filename = UUID.randomUUID() + ".jpg";//文件名+后缀名
String originalFilename = uploadPath + tbYingqushebei.getCampId() + File.separator + filename;
log.info("图片路径:{}", uploadPath + tbYingqushebei.getCampId() + File.separator + filename);
FileUtils.generateImage(zhoujieruqingaojingjiluAO.getGaojingtupian(), originalFilename);
File originalFile = new File(originalFilename);
DiskFileItem fileItem = new DiskFileItem("file", "image/jpeg", false, originalFile.getName(), (int) originalFile.length(), originalFile.getParentFile());
try (InputStream input = new FileInputStream(originalFile); OutputStream os = fileItem.getOutputStream()) {
IOUtils.copy(input, os);
log.info(fileItem.getStoreLocation() + "--getStoreLocation");
} catch (Exception e) {
throw new IllegalArgumentException("Invalid file:" + e, e);
}
MultipartFile multipartFile = new CommonsMultipartFile(fileItem);
// 调用文件上传服务上传告警图片
R<SysFile> file = remoteFileService.upload(multipartFile);
SysFile sysFile = file.getData();
if (ObjectUtils.isNotEmpty(originalFile) && originalFile.exists()) {
originalFile.delete();
}
log.info("周杰告警图片url--{}", sysFile.getUrl());