MultipartFile 转 java.io.File
作者:互联网
一般用来File的直接操作不产生系统文件,只产生一个临时文件
import com.chenkang.decheng.util.WebLfasrDemo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
@RestController
@RequestMapping(value = "audio",produces = "text/plain;charset=UTF-8")
@CrossOrigin
public class AudioController {
@PostMapping
public String uploadAudio(MultipartFile audio) throws IOException {
// 获取文件名
String fileName = audio.getOriginalFilename();
// 获取文件后缀
String prefix=fileName.substring(fileName.lastIndexOf("."));
// 用uuid作为文件名,防止生成的临时文件重复
File excelFile = File.createTempFile(UUID.randomUUID().toString(),prefix);
// MultipartFile to File
System.out.println(excelFile.getPath());
audio.transferTo(excelFile);
//程序结束时,删除临时文件
return WebLfasrDemo.transformAudio(excelFile);
}
}
标签:web,java,springframework,excelFile,File,org,import,MultipartFile 来源: https://blog.csdn.net/weixin_38845058/article/details/100670632