1

根据https://github.com/transloadit/uppy-vimeo-thing/blob/master/Vimeo.js中的代码,我有下面的课程。

恢复上传不起作用,它总是从头开始重新上传。如果我uploadUrl从 Tus 选项中删除并将endpoint值设置为https://master.tus.io/files/(因此不上传到 Vimeo),则恢复上传按预期工作。仅在将上传内容发送到 Vimeo 时才会出现此问题。

查看我的开发人员工具的网络选项卡,我发现upload-offset总是0在将 PATCH 请求发送到 Vimeo 时,即使在恢复它(后续请求)时也是如此。

const { Plugin } = require('@uppy/core')
const mapLimit = require('promise-map-limit')

const VIMEO_API_ROOT = 'https://api.vimeo.com'

class Vimeo extends Plugin {
  constructor (uppy, opts) {
    super(uppy, opts)

    this.name = 'Vimeo'
    this.id = 'Vimeo'
    this.type = 'uploader'

    this.opts = Object.assign({
      limit: 100
    }, this.opts)

    this.prepareUpload = this.prepareUpload.bind(this)
    this.afterUpload = this.afterUpload.bind(this)
  }

  async prepareUpload (fileIDs) {
    const { videoTitle } = this.opts

    fileIDs.forEach((fileID) => {
      this.uppy.emit('preprocess-progress', fileID, {
        mode: 'indeterminate',
        message: 'Creating video...'
      })
    })

    await mapLimit(fileIDs, this.opts.limit, async (fileID) => {
      const file = this.uppy.getFile(fileID)
      const response = await fetch(`${VIMEO_API_ROOT}/me/videos`, {
        method: 'post',
        headers: {
          'authorization': `Bearer ${vimeoAccessToken}`,
          'content-type': 'application/json',
          'accept': 'application/vnd.vimeo.*+json;version=3.4'
        },
        body: JSON.stringify({
          upload: {
            approach: 'tus',
            size: file.size
          },
          name: videoTitle
        })
      })

      const { upload, link, uri } = await response.json()
      this.uppy.setFileState(fileID, {
        uploadURL: link,
        vimeo: {
          link,
          id: uri.split('/').pop()
        },
        tus: Object.assign({}, file.tus, {
          endpoint: 'https://files.tus.vimeo.com/files/', // HACK this is to appease tus-js-client
          // NOTE: This is uploadUrl instead of endpoint, different from what you might expect;
          // Vimeo pre-creates the Tus upload.
          uploadUrl: upload.upload_link,
          headers: {
            'Accept': 'application/vnd.vimeo.*+json;version=3.4'
          }
        }),
      })

      this.uppy.emit('preprocess-complete', fileID)
    })
  }

  async afterUpload (fileIDs) {
    fileIDs.forEach((fileID) => {
      const file = this.uppy.getFile(fileID)
      const video = file.vimeo

      this.uppy.setFileState(fileID, {
        uploadURL: video.link
      })
    })
  }

  install () {
    this.uppy.addPreProcessor(this.prepareUpload)
    this.uppy.addPostProcessor(this.afterUpload)
  }

  uninstall () {
    this.uppy.removePreProcessor(this.prepareUpload)
    this.uppy.removePostProcessor(this.afterUpload)
  }
}

module.exports = Vimeo

4

1 回答 1

0

看到这个评论它会解决它我必须在我的'new tus.Upload()'中设置chunkSize变量。默认情况下,chunkSize 是无限的,似乎 Vimeo 的“上传偏移”响应仅针对已完成的块,因此在上传完成之前没有已完成的块。通过将其设置为 5000000 (5mb),我可以成功暂停和恢复上传。恢复后,它会在最后一个完成的块处重新启动。

于 2021-03-30T02:53:31.780 回答