问题描述
据我所知,可以使用curl发出POST和PATCH请求;
As I understand, one can use curl to make POST and PATCH requests;
POST:
PATCH:
Vimeo API支持POST和PATCH请求以上传视频;
And the Vimeo API support POST and PATCH requests to upload a video;
这是我最好的猜测关于如何写;
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}" }}'
我怀疑这充满了错误,并且也没有显示如何上传带有PATCH请求的视频。
I suspect this is full of errors, and it also does not show how to upload a video with PATCH requests.
正确的curl命令是什么样的?
What would the correct curl command(s) look like?
推荐答案
对于使用Vimeo API上传tus,这是一个多步骤过程:
For tus upload using the Vimeo API, it's a multi-step process:
- 在Vimeo上创建视频对象
- 上传视频文件数据
- 验证Vimeo已收到您的视频文件
第1步是对 / me / videos
的POST请求。如果操作正确,您将收到完整的视频回复,其中包含 upload
对象,其中包含 upload_link
。在步骤2中使用 upload_link
值。
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.
(请注意, upload_link
应该位于Vimeo的 tus子域上,例如 files.tus.vimeo.com
。如果您获得 upload_link
在另一个Vimeo子域上,则您的请求出了点问题,并且该API默认使用另一种上传方法。您还可以验证自己是否获得了tus upload_link $ c $通过检查嵌套在
upload
对象中的方法
值返回的c>,它应该返回 tus。)
(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".)
在您的示例中,-请求
缺少 POST
动词/行动。步骤1应该看起来像这样(还请注意-请求
,标头
和-数据
可与 -X
, -H
和互换-d
):
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"}}'
第2步,实际的文件上传是对 upload_link
返回的PATCH从步骤1开始,请求主体包含视频文件的原始二进制数据:
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
第3步是对同一 upload_link
的HEAD请求,没有文件数据:
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' \
取决于返回的 upload-length
和 upload-offset
标头,您可能需要重复第2步,从Vimeo服务器上的最后一个字节恢复上传。
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.
Vimeo tus tus上传实现的文档位于:
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!
这篇关于使用其API和curl(POST / PATCH)将视频上传到Vimeo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!