用于替换 Vimeo 中现有视频的脚本 .bat 不起作用。使用 API 和 curl

问题描述 投票:0回答:0

我正在为 Windows 创建一个 .bat 脚本,使用 VIMEO API 和 curl 将一个视频替换为另一个视频。 该脚本工作正常,直到最后一部分我进行 PATH 调用并收到此错误消息:“缺少或无效的 Upload-Length 标头” 这是脚本代码:

@echo off
CLS
REM For security reason dont write the real access_token 
set "access_token=xxxxxxxxxxxxx"
set "video_id=818155814"
set "video_path=Prueba_INS.mp4"
set "file_name=Prueba_INS.mp4"
set "curl=C:\INFO_LOCAL_UL\CURL\bin\curl.exe"
set "jq=C:\INFO_LOCAL_UL\jq\jq-win64.exe"

:: Get the size of the video file in bytes
   Echo Get the size of the video file in bytes
   for %%I in ("%video_path%") do set "file_size=%%~zI"
   Echo value of new video file_size: %file_size%
   Echo.

:: Create a JSON payload for the POST request
   Echo Create a JSON payload for the POST request
   if exist payload.json del /F /Q payload.json
   echo { "file_name": "%file_name%", "upload": { "status": "in_progress", "size": "%file_size%", "approach": "tus" } } > payload.json
   Echo value of payload.json: 
   Type payload.json
   Echo.

:: Send a POST request to /videos/{video_id}/versions
   Echo Send a POST request to /videos/{video_id}/versions
   if exist response.json del /F /Q response.json
   %curl% -X POST "https://api.vimeo.com/videos/%video_id%/versions" --header "Content-Type: application/json" --header "Authorization: Bearer %access_token%" --header "Accept: application/vnd.vimeo.*+json;version=3.4" -d "@payload.json" -o response.json

:: Get the size of response.json file in bytes
   Echo Get the size of response.json file in bytes
   for %%I in ("response.json") do set "file_size_response=%%~zI"
   
:: Extract the upload link for the new video
   Echo Extract the upload link for the new video
   if exist upload_link.txt del /F /Q upload_link.txt
   type response.json | %jq% ".upload.upload_link" -r > upload_link.txt
   set /p upload_link=<upload_link.txt
   Echo value of upload_link: %upload_link%
   Echo.

:: upload for the new video
   %curl% -X PATCH "%upload_link%" -H "Upload-Offset: 0" -H "Content-Type: application/offset+octet-stream" -H "Tus-Resumable: 1.0.0" -H "Upload-Length:%file_size%" --upload-file "%video_path%"

echo Video replaced successfully!

这是我的脚本的输出,显示一切正常,包括获取文件大小。

Get the size of the video file in bytes
value of new video file_size: 639475195

Create a JSON payload for the POST request
value of payload.json:
{ "file_name": "Prueba_INS.mp4", "upload": { "status": "in_progress", "size": "639475195", "approach": "tus" } }

Send a POST request to /videos/{video_id}/versions
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15487    0 15374  100   113   2686     19  0:00:05  0:00:05 --:--:--  4425
Get the size of response.json file in bytes
value of size for response.json: 15374

Extract the upload link for the new video
value of upload_link: https://us-files.tus.vimeo.com/files/vimeo-prod-src-tus-us/e4635cfd45043efef78b98bbc9a236ae

missing or invalid Upload-Length header
Video replaced successfully!

有人可以指导我解决此错误的原因和可能的解决方案。

我做了一个curl的配置文件,调用是这样的: %curl% --config curl_config_modified.txt curl_config_modified.txt 的内容是:

url = "https://us-files.tus.vimeo.com/files/vimeo-prod-src-tus-us/479c393bd0bdea42c811eb6d4d5a6ead"
request = "PATCH"
header = "Upload-Offset: 0"
header = "Content-Type: application/offset+octet-stream"
header = "Tus-Resumable: 1.0.0"
header = "Upload-Length: 639475195"
upload-file = "Prueba_INS.mp4"

*------------

但是,我总是收到相同的错误消息:“上传长度标头丢失或无效”

api curl replace vimeo vimeo-api
© www.soinside.com 2019 - 2024. All rights reserved.