将 File 对象 转成 MultipartFile 对象
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
import org.springframework.mock.web.MockMultipartFile;
String filepath = "你的文件地址" //如 D://image/pic.png
File file = new File(filepath);
//上传本地项目的图片
FileInputStream fileInputStream = new FileInputStream(file);
// ContentType.IMAGE_JPEG.toString() 这是你的文件类型 ,我这是图片
MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(), ContentType.IMAGE_JPEG.toString(), fileInputStream);