1、html部分
<label class="btn" for="uploadsvideo" style="margin-left: 15px;">視頻上傳</label>
<span style="display: inline-block;margin-top: 20px;color: red">*上傳本地視頻至素材庫</span>
<input type="file" id="uploadsvideo" name="file" multiple="multiplt"
style="position:absolute; clip:rect(0 0 0 0);"
accept="audio/3gpp, video/3gpp,audio/mp4, video/mp4,video/mpeg" @change="uploadVideo($event, 1)">
2豁护、js部分
async upload (data) {
let res = await api.material.uploadFile(data)
if (res.data.return_code === 'SUCCESS') {
this.$Message.success('上傳成功')
} else {
this.$Message.error('上傳失敗')
}
},
// base64轉(zhuǎn)blob
dataURLtoBlob (dataurl) {
let arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length,
u8arr = new Uint8Array(n)
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
}
return new Blob([u8arr], {type: mime})
},
// 多文件上傳
uploadVideo (e, num) {
// this.option.img
if (!/\.(rm|rmvb|wmv|avi|mp4|3gp|mkv)$/.test(e.target.value)) {
alert('請上傳視頻格式文件')
return false
} else {
let _this = this
let fileList = e.target.files
console.log(fileList)
for (let i in fileList) {
let reader = new FileReader()
reader.readAsDataURL(fileList[i])
reader.onloadend = function () {
let base64 = reader.result // base64就是圖片的轉(zhuǎn)換的結(jié)果
console.log(base64)
console.log(_this.dataURLtoBlob(base64))
_this.upload(_this.dataURLtoBlob(base64)) // 多文件循環(huán)上傳
}
}
}
}
},