vimeo / vimeo.js

Official Node.js library for the Vimeo API.
https://developer.vimeo.com
Apache License 2.0
267 stars 78 forks source link

Vimeo Client ignores any upload paramaters #176

Closed keepflying1 closed 1 year ago

keepflying1 commented 1 year ago

I am trying to upload to Vimeo via a pull request, as mentioned extensively in the documentation.

I am able to upload local files, but have not been able to upload an externally hosted, publicly accessible video hosted on S3.

I have read the documentation extensively, my client/secret/token keys are correct, my account allows uploads.

As best as I can tell, the Vimeo client outright ignores any upload approaches, overwriting them with TUS, in lines 639 - 648 of vimeo.js:

  // Ignore any specified upload approach and size.
  if (typeof params.upload === 'undefined') {
    params.upload = {
      approach: 'tus',
      size: fileSize
    }
  } else {
    params.upload.approach = 'tus'
    params.upload.size = fileSize
  }

There is a similar block of code in Vimeo's PHP script. I switched to NodeJS, thinking maybe it was just a language deficiency, only to find that upload approaches are similarly ignored in NodeJS as well.

At $900/yr, this is simply unacceptable; I'd understand if this was an open source labor of love, but as best I can tell this is an official Vimeo product*. I even tried hacking the offending lines without much luck, but after a certain point I need to turn back to Vimeo and demand better.

System Information OS: Ubuntu 20.04.5 NodeJs: v16.19.1 Vimeo NPM: 3.0.0

Suggested Fixes

Or

*If I'm wrong and this is not a Vimeo product, please accept my apologies to the contributors, I meant no disrespect. My frustration is entirely directed at Vimeo, the company.

hedyyytang commented 1 year ago

Hi @keepflying1 , sorry for the frustration. The upload method in the SDK is intended for tus only. You should be able to achieve upload via pull through the regular request call

const url = 'url'
const size = 'size'

const uploadByPull = async (url, size) => {
  const res = await client.request(
    {
      hostname: 'api.vimeo.com',
      path,
      headers: {
        Authorization: 'bearer ' + token,
        'Content-Type': 'application/json',
        Accept: 'application/vnd.vimeo.*+json;version=3.4'
      },
      method: 'POST',
      body: {
        upload: {
          approach: 'pull',
          size,
          link: url
        }
      }
    }
  ).catch(e => console.log(e))
  console.log(res)
}

uploadByPull(url, size)

Let me know if this works for you.

keepflying1 commented 1 year ago

The above works, with one change: swapping "body" for "query".

Here's my completed code:

var url         = 'url';
var filesize    = 'filesize';
var token       = 'token';
const response  = await client.request({
    'hostname': 'api.vimeo.com',
    'path':     "/me/videos",
    'headers': {
        'Authorization': 'bearer ' + token,
        'Content-Type': 'application/json',
        'Accept': 'application/vnd.vimeo.*+json;version=3.4'
    },  
    'method': 'POST',
    'query': {
        'upload': {
            'approach':     'pull',
            'size':         filesize,   // in bytes
            'link':         url,
        },
        'name':             'Test Name',
        'description':      'description test',
        'privacy':      {
            'view':         'nobody',
        },  
    }
}).catch(error => console.log(`ERROR:`+error));

Apologies that I let my frustration get the better of me. Appreciate the help!