1
fileChange (data) {
console.log(data)
this.file = data.file
if (!this.file) {
alert("请先选择需要上传的文件!")
return
}
var Title = this.file.name
var userData = '{"Vod":{}}'
if (this.uploader) {
this.uploader.stopUpload()
this.authProgress = 0
this.statusText = ""
}
this.uploader = this.createUploader()
console.log(userData)
this.uploader.addFile(this.file, null, null, null, userData)
this.uploadDisabled = false
this.pauseDisabled = true
this.resumeDisabled = true
this.authUpload()
},
authUpload () {
if (this.uploader !== null) {
this.uploader.startUpload()
this.uploadDisabled = true
this.pauseDisabled = false
}
},
pauseUpload () {
if (this.uploader !== null) {
this.uploader.stopUpload()
this.resumeDisabled = false
this.pauseDisabled = true
}
},
resumeUpload () {
if (this.uploader !== null) {
this.uploader.startUpload()
this.resumeDisabled = true
this.pauseDisabled = false
}
},
createUploader (type) {
let self = this
let uploader = new AliyunUpload.Vod({
timeout: self.timeout || 60000,
partSize: self.partSize || 1048576,
parallel: self.parallel || 5,
retryCount: self.retryCount || 3,
retryDuration: self.retryDuration || 2,
region: self.region,
userId: self.userId,
addFileSuccess: function (uploadInfo) {
self.uploadDisabled = false
self.resumeDisabled = false
self.statusText = '添加文件成功, 等待上传...'
console.log(uploadInfo)
console.log("addFileSuccess: " + uploadInfo.file.name)
},
onUploadstarted: function (uploadInfo) {
console.log(uploadInfo)
if (!uploadInfo.videoId) {
let params = {
title: uploadInfo.file.name,
fileName: uploadInfo.file.name
}
getCreateUploadVideoResponse(params).then(res => {
let data = JSON.parse(res.data)
let { uploadAuth,uploadAddress,videoId} = data;
uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress,videoId)
})
self.statusText = '文件开始上传...'
} else {
}
},
onUploadSucceed: function (uploadInfo) {
self.statusText = '文件上传成功!'
setTimeout(() => {
self.isUpload = false;
},1000)
self.addParams.videoId = uploadInfo.videoId;
},
onUploadFailed: function (uploadInfo, code, message) {
self.statusText = '文件上传失败!'
},
onUploadCanceled: function (uploadInfo, code, message) {
self.statusText = '文件已暂停上传'
},
onUploadProgress: function (uploadInfo, totalSize, progress) {
let progressPercent = Math.ceil(progress * 100)
self.authProgress = progressPercent
self.statusText = '文件上传中...'
self.progressPercent = Math.ceil(progress * 100)
},
onUploadTokenExpired: function (uploadInfo) {
let refreshUrl = 'https://demo-vod.cn-shanghai.aliyuncs.com/voddemo/RefreshUploadVideo?BusinessType=vodai&TerminalType=pc&DeviceModel=iPhone9,2&UUID=59ECA-4193-4695-94DD-7E1247288&AppVersion=1.0.0&Title=haha1&FileName=xxx.mp4&VideoId=' + uploadInfo.videoId
axios.get(refreshUrl).then(({data}) => {
let uploadAuth = data.UploadAuth
uploader.resumeUploadWithAuth(uploadAuth)
console.log('upload expired and resume upload with uploadauth ' + uploadAuth)
})
self.statusText = '文件超时...'
},
onUploadEnd: function (uploadInfo) {
console.log("onUploadEnd: uploaded all the files")
self.statusText = '文件上传完毕'
}
})
return uploader
}