前端上传阿里云后解析文件,获取宽高时长等信息传给后端
export function fileHandle(ossInfo, response, file, type) {
let path = `http://${ossInfo.data.bucket}.oss-cn-shenzhen.aliyuncs.com/${response.name}` //文件线上地址
let visit_screen_shot = path + '?x-oss-process=video/snapshot,t_1000,f_jpg,w_0,h_0' //阿里云文件截图
let url = URL.createObjectURL(file.file);
let audioElement = new Audio(url);
let img = new Image()
return new Promise(resolve => {
if (type == 1) {
audioElement.addEventListener("loadedmetadata",()=> {
// 获取上传的视频的宽高
let video = document.createElement("video");
video.src = url;
video.onloadedmetadata = ()=> {
URL.revokeObjectURL(url); //释放当前视频对象
response.visit_screen_shot = visit_screen_shot
response.visit_path = path
response.video = response.name
response.width = video.videoWidth
response.height = video.videoHeight
response.duration = audioElement.duration;
//获取成功后返回结果
resolve(response)
};
});
}else {
img.src = path
img.onload = ()=> {
response.visit_screen_shot = path
response.path = response.name
response.width = img.width
response.height = img.height
resolve(response)
};
}
}).catch(error=> {
console.log(error);
})
}