controller
@PostMapping("/upload")
public List<?> uploadFiles(@RequestParam(value = "file") MultipartFile[] files, @RequestParam(value = "path") String path) {
return null;
}
feign
@RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
List<?> uploadFiles(@RequestPart("file") MultipartFile[] file, @RequestPart("path") String path);
File或者路径 转成 MultipartFile
public static MultipartFile getMultipartFile(File file) {
FileInputStream fileInputStream;
MultipartFile multipartFile = null;
try {
fileInputStream = new FileInputStream(file);
multipartFile = new MockMultipartFile(file.getName(), file.getName(),
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
} catch (Exception e) {
e.printStackTrace();
}
return multipartFile;
}
public static MultipartFile getMultipartFile(String filePath) {
try {
FileInputStream fileInputStream = new FileInputStream(filePath);
return new MockMultipartFile(filePath, filePath,
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}