| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import PlvVideoUpload from '@polyv/vod-upload-js-sdk'
- import api from '@/api/api'
- // import md5 from 'js-md5'
- // 此方法主要用于加密一些保利威的专用参数 如果是后端传递的 可以打掉
- function getToken(videoUpload, array) {
- const ptime = array.ptime
- const userid = 'd5f6d309fe'
- // const secretkey = 'xpPrYdcbA1'
- // const writeToken = '8f14a371-9d02-4ec1-922d-54d7b4f79dca'
- const hash = array.hash
- const sign = array.sign
- // const hash = md5(ptime + writeToken)
- // const sign = md5(secretkey + ptime)
- videoUpload.updateUserData({ ptime, hash, sign, userid })
- videoUpload.startAll()
- }
- // 由于保利威的一些机制 你需要三分钟就重新加密你的 ptime 如果你打掉了就不行
- function autoUpdateUserData(timer, videoUpload, array) {
- getToken(videoUpload, array)
- if (timer) {
- clearTimeout(timer)
- timer = null
- }
- timer = setTimeout(() => {
- autoUpdateUserData(timer, videoUpload, array)
- }, 3 * 50 * 1000)
- }
- /**
- * @Date: 2021/3/26
- * @param: files -> 一个文件的数组 注意 是【数组】
- * @param: fileSetting -> 主要是用来传递给保利威的属性
- * @param: callback -> 上传进度,成功,失败 的回调 tips:回调太多 我就拿了这三个比较有用的
- */
- export function uploadFile(files, fileSetting, callback) {
- const videoUpload = new PlvVideoUpload({
- region: 'line1', // (可选)上传线路, 默认line1
- events: {
- Error: (err) => { // 错误事件回调
- console.log(err);
- },
- UploadComplete: () => { } // 全部上传任务完成回调
- }
- })
- console.log(videoUpload,'init')
- new Promise((resolve, reject) => {
- api.inquirepolyvvideogetPolyvUpload().then(res => {
- resolve(res)
- })
- }).then(res => {
- autoUpdateUserData(null, videoUpload, res.data)
- var filet = [files]
- Array.from(filet).forEach((file, index) => {
- console.log(videoUpload, 1121)
- const uploader = videoUpload.addFile(file, {
- // 上传视频进度的回调
- FileProgress: ({ progress }) => {
- const progressSize = (progress * 100).toFixed(2)
- callback(index, progressSize)
- },
- // 上传视频成功的回调
- FileSucceed: ({ fileData }) => {
- callback(index, fileData)
- },
- // 上传视频失败的回调
- onFileFailed: ({ errData }) => {
- callback(index, errData)
- }
- }, fileSetting)
- // console.log(uploader)
- })
- })
- /**
- * 这里的调用是上传全部
- * 本来我也是一个一个调的
- * 但是考虑到对于有多选上传不是很友好
- * 就无论你传递几个视频 这里都统一一起上传
- * */
-
- }
|