pom:
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.4</version>
</dependency>
1、controller接收文件:
public Result<?> validateResult(@RequestParam("file") MultipartFile megLiveData) {
}
2、MultipartFile转换为File
try{
File file = null;
//将MultipartFile转换为File
file = new File(megLiveData.getOriginalFilename());
FileUtils.copyInputStreamToFile(megLiveData.getInputStream(), file);
}catch(Exception e){
throw new RuntimeException();
}
finally {
//这种方法会产生临时文件,用完后需要删除
if<