前端上傳阿里云后解析文件,獲取寬高時長等信息傳給后端
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); //釋放當(dāng)前視頻對象
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;
//獲取成功后返回結(jié)果
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);
})
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。