Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for uploading pictures #92

Open
erunion opened this issue Dec 11, 2018 · 5 comments
Open

Add support for uploading pictures #92

erunion opened this issue Dec 11, 2018 · 5 comments

Comments

@erunion
Copy link
Contributor

erunion commented Dec 11, 2018

We have support for uploading pictures in our PHP SDK and would be nice to have that functionality here too.

Upload documentation: https://developer.vimeo.com/api/upload/thumbnails

@positlabs
Copy link

I am working on this for my own purposes. I'm sure my code could be ported over easily, but I'm getting hung up on the last step.

  const reqActiveOpts = {
    method: 'PATCH',
    url: `https://api.vimeo.com${thumbURI}`,
    headers: {
      'Authorization': `bearer ${env.VIMEO_ACCESS_TOKEN}`,
      'Content-Type': 'application/json',
      'Accept': 'application/vnd.vimeo.*+json;version=3.4',
    },
    data: {
      active: true
    },
  }
  const thumbActiveResponse = await axios(reqActiveOpts)

It always responds with Error: Request failed with status code 405 (method not allowed)

@positlabs
Copy link

positlabs commented Jun 11, 2019

Reading is hard sometimes. I figured it out.

Here is what I ended up with. Could add an option for setting active state.


const uploadPoster = async (imageURL, thumbURI) => {
  console.log('uploadPoster', imageURL, thumbURI)

  const thumbFilepath = `/tmp/${imageURL.split('/').pop()}`
  const thumbDownload = await axios({
    method: 'get',
    url: imageURL,
    responseType: 'stream'
  })
  await new Promise((resolve, reject) => {
    const stream = thumbDownload.data.pipe(fs.createWriteStream(thumbFilepath))
    stream.on('error', reject)
    stream.on('finish', resolve)
  })

  const createThumbOpts = {
    method: 'POST',
    url: `https://api.vimeo.com${thumbURI}`,
    headers: {
      'Accept': 'application/vnd.vimeo.*+json;version=3.4',
      'Authorization': `bearer ${env.VIMEO_ACCESS_TOKEN}`
    },
    data: fs.readFileSync(thumbFilepath),
  }
  const createThumbResponse = await axios(createThumbOpts)

  const reqOpts = {
    method: 'PUT',
    url: createThumbResponse.data.link,
    headers: {
      'Accept': 'application/vnd.vimeo.*+json;version=3.4',
      'Content-Type': 'image/' + thumbFilepath.split('.').pop(),
      'Authorization': `bearer ${env.VIMEO_ACCESS_TOKEN}`
    },
    data: fs.readFileSync(thumbFilepath),
  }
  const thumbResponse = await axios(reqOpts)

  const reqActiveOpts = {
    method: 'PATCH',
    url: `https://api.vimeo.com${createThumbResponse.data.uri}`,
    headers: {
      'Authorization': `bearer ${env.VIMEO_ACCESS_TOKEN}`,
      'Content-Type': 'application/json',
      'Accept': 'application/vnd.vimeo.*+json;version=3.4',
    },
    data: {
      active: true
    },
  }
  const thumbActiveResponse = await axios(reqActiveOpts).catch(err => console.error(err))

  return thumbActiveResponse
}

@csillag
Copy link

csillag commented Jun 12, 2020

    headers: {
      'Accept': 'application/vnd.vimeo.*+json;version=3.4',
      'Content-Type': 'image/' + thumbFilepath.split('.').pop(),
      'Authorization': `bearer ${env.VIMEO_ACCESS_TOKEN}`
    },

Actually, authorization is not required here. (It's done in the previous step; in the current step, the signature embedded in the upload URL does the trick.)

@majdkilou
Copy link

how can I use it to upload thumbnail to my video.
my thumbnail uri is `https://api.vimeo.com/videos/${videoId}/pictures'

@karlhorky
Copy link
Contributor

Anyone who is coming here to try to create thumbnails from a frame of the video, you can check out my comment over here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants