通过spring mvc获取的文件是.tmp文件(临时文件)
随意上传到第三方服务时无法解析。。
so, 本来想看看能不能直接对File重命名,结果
String realPath = request.getSession().getServletContext()
.getRealPath("/resources/upload/res");
File tempFile = null;
if (!myfile.isEmpty()) {
// 获得原始文件名
String fileName = myfile.getOriginalFilename();
//获得物理路径webapp所在路径
String pathRoot = request.getSession().getServletContext().getRealPath("/resources/upload/res");
// 项目下相对路径
String path = File.separator + fileName;
// 创建文件实例
tempFile = new File(pathRoot + path); //文件保存路径为pathRoot + path
if (!tempFile.getParentFile().exists()) {
tempFile.getParentFile().mkdir();
}
if (!tempFile.exists()) {
tempFile.mkdir();
}
try {
// Transfer the received file to the given destination file.
myfile.transferTo(tempFile);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
···
本质来说就时通过新建文件来重命名
然后在上传,第三方服务可以正常解析视频文件