Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

javascript - tus-js-client function onProgress no update after refreshing page

I am uploading videos to vimeo from my frontend, using tus-js-client. The load happens without problems and everything works fine, the onProgress function receives the load data fine. I am using vue and these are the functions that I use to load.

async vimeoQueryLink () {
  try {
    const { size } = this.upload.video

    const body = {
      name: Number(new Date()).toLocaleString(),
      upload: {
        approach: 'tus',
        size
      }
    }

    const response = await fetch('https://api.vimeo.com/me/videos', {
      method: 'POST',
      mode: 'cors',
      cache: 'no-cache',
      credentials: 'same-origin',
      headers: {
        Authorization: 'bearer TOKEN',
        'Content-Type': 'application/json',
        Accept: 'application/vnd.vimeo.*+json;version=3.4'
      },
      redirect: 'follow',
      referrerPolicy: 'no-referrer',
      body: JSON.stringify(body)
    })

    return response.json()
  } catch (error) {
    console.log(error)
  }
}
    
async vimeoUploadVideo () {
  const { upload } = await this.vimeoQueryLink()

  const tusUpload = new tus.Upload(this.upload.video, {
    uploadUrl: upload.upload_link,
    onError (error) {
      console.log('vimeoUploadVideo: error =>' + error)
    },
    onProgress (bytesUploaded, bytesTotal) {
      /**
      *   After refreshing the page, it only shows when it starts and when it loads 100%
      **/
      
      const percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
      console.log(bytesUploaded, bytesTotal, percentage + '%')
    },
    onSuccess () { 
      console.log('Download %s from %s', tusUpload.file.name, tusUpload.url)
      console.log('vimeoUploadVideo: finish')
    }
  })

  tusUpload.start()
}
question from:https://stackoverflow.com/questions/65648627/tus-js-client-function-onprogress-no-update-after-refreshing-page

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...