String linuxpath = "/data/config/program/video";
String windowpath = "D:/tempFiles";
path = System.getProperty("os.name").toLowerCase().contains("linux") ? linuxpath : windowpath;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
// 判断文件夹是否存在,如果不存在则创建文件夹
File tempFolder = new File("temp");
if (!tempFolder.exists()) {
tempFolder.mkdir();
}
this.PROCESS_VIDEO_FOLDER = path + "/" + "process_video";
if(!Objects.equals(FilenameUtils.getExtension(file.getOriginalFilename()), "mp4")){
return new Response("您上传的视频格式不是mp4,请转码为20兆以内的AVC(H264)编码格式的mp4文件后再上传",false);
}
if(file.getSize()>(20*1050000)){
return new Response("您上传的视频文件超大,请转码为20兆以内的AVC(H264)编码格式mp4文件后再上传",false);
}
String videoId = new ObjectId().toString();
String tempPath = "temp" + "/" + videoId + "." + FilenameUtils.getExtension(file.getOriginalFilename());
try {
File inputFile = new File(tempPath);
FileUtils.copyInputStreamToFile(file.getInputStream(), inputFile);
File video = new File(PROCESS_VIDEO_FOLDER + "/" + videoId + ".mp4");
FileUtils.moveFile(inputFile, video);
return new Response(videoId);
} catch (IOException e) {
e.printStackTrace();
return new Response("");
}
视频上传到指定目录
最新推荐文章于 2024-07-14 22:18:32 发布