2

As I understand, one can use curl to make POST and PATCH requests;

POST: https://gist.github.com/subfuzion/08c5d85437d5d4f00e58

PATCH: How to use PATCH verb with curl

And the Vimeo API support POST and PATCH requests to upload a video;

https://developer.vimeo.com/api/upload/videos

Here is my best guess so far as to how this can be written;

curl --request --url https://api.vimeo.com/me/videos \
--header 'Authorization: bearer {access_token}' \
--header 'Content-Type: application/json' \
--header 'Accept: application/vnd.vimeo.*+json;version=3.4' \
--data '{ "upload": { "approach": "tus", "size": "{size}" }}'

I suspect this is full of errors, and it also does not show how to upload a video with PATCH requests.

What would the correct curl command(s) look like?

Roel Van de Paar
  • 2,111
  • 1
  • 24
  • 38

1 Answers1

6

For tus upload using the Vimeo API, it's a multi-step process:

  1. Create the video object on Vimeo
  2. Upload the video file data
  3. Verify that Vimeo has received your video file

Step 1 is the POST request to /me/videos. If done correctly, you'll receive the full video response back, with an "upload" object containing an "upload_link". Use the upload_link value for Step 2.

(Note that the upload_link should be on a Vimeo "tus" subdomain, like files.tus.vimeo.com. If you get an upload_link on a different Vimeo subdomain, then something went wrong with your request and the API is defaulting to another upload approach. You can also verify that you're getting a tus upload_link returned by checking the approach value nested in the upload object, it should return "tus".)

From your example, --request lacks the POST verb/action. Step 1 should look like this (also note that -request, -header, and -data are interchangeable with -X, -H, and -d, respectively):

curl -X POST https://api.vimeo.com/me/videos \
  -H 'Accept: application/vnd.vimeo.*+json;version=3.4' \
  -H 'Authorization: bearer XXXXXXXXX' \
  -H 'Content-Type: application/json' \
  -d '{"upload":{"approach":"tus","size":"999999"}}'

Step 2, the actual file upload, is a PATCH to the upload_link returned from Step 1, with the request body containing the raw binary data of your video file:

curl --request PATCH upload_link \
  -H 'Accept: application/vnd.vimeo.*+json;version=3.4' \
  -H 'Content-Type: application/offset+octet-stream' \
  -H 'Tus-Resumable: 1.0.0' \
  -H 'Upload-Offset: 0' \
  --data-binary /path/to/file.ext

Step 3 is a HEAD request to that same upload_link, without the file data:

curl --request HEAD upload_link \
  -H 'Accept: application/vnd.vimeo.*+json;version=3.4' \
  -H 'Tus-Resumable: 1.0.0' \

Depending on the upload-length and upload-offset headers returned, you may need to repeat step 2, resuming the upload from the last byte on Vimeo's servers.

Documentation for Vimeo's tus upload implementation is found here: https://developer.vimeo.com/api/upload/videos#resumable-approach

Hope this points you in the right direction!

Tommy Penner
  • 2,910
  • 1
  • 11
  • 16
  • few questions; 1) what does `bearer XXXXXXXXX` stand for, and how do I pass the auth key? Also, do subsequent calls require this authentication again? 2) Is there any way to just re-do the upload if it fails instead of byte-splitting it? 3) I was surprised to see that my `--data`/`-d` thoughts were about correct. It is really possible to just sent ASCII data like that? Thank you again, very much. I may have some more questions later. – Roel Van de Paar Aug 01 '19 at 23:31
  • 1
    @Roel 1) `XXXXXX` is where you should insert your auth token, and every request to `api.vimeo.com` requires a token: https://developer.vimeo.com/api/authentication#presenting-the-access-token. 2) In theory you could just perform a replacement/new version upload. Instead of doing a POST /me/videos, you'd do a POST to the `/versions` uri returned in Step 1. Replacement upload docs: https://developer.vimeo.com/api/upload/videos#replacing-a-source-file. 3) Yeah you should be able to use `-d` just as described, check curl docs for full details: https://curl.haxx.se/docs/manpage.html#-d – Tommy Penner Aug 02 '19 at 16:03
  • 1
    under step 2: how to give the data @TommyPenner can u give an example. I used the following code:- `--data-binary '/home/abhi/intership/vimeo/1.mp4' ` – Abhishek Nov 13 '19 at 18:25
  • Bringing this up from the dead, but I'm currently facing this problem and I'm unsure how to structure the body of step 2, particularly for uploading a file from a local device (computer or mobile phone), how the path would work. – David Avellan Aug 30 '23 at 18:19