Java-File转MultipartFile

Java-File转MultipartFile

1、依赖

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.2.7.RELEASE</version>
        </dependency>    

2、代码     

String filePaht = "";
File imageFile = new File(filePath); FileInputStream in = new FileInputStream(imageFile); MultipartFile file = new MockMultipartFile("file", imageFile.getName(), "text/plain", IOUtils.toByteArray(in));

 

上一篇:RestTemplate发送MultipartFile为参数的请求


下一篇:springboot实现文件上传