问题
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?
回答1:
For tus upload using the Vimeo API, it's a multi-step process:
- Create the video object on Vimeo
- Upload the video file data
- 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!
来源:https://stackoverflow.com/questions/57300880/upload-a-video-to-vimeo-using-their-api-and-curl-post-patch