分片上传:上传一片
PUT /v1/videos/references/uploads/{upload_id}/parts/{part_number}参考素材上传涉及大文件和分片上传,这组接口不提供在线调用,请使用示例代码。
上传第 part_number 片,请求体是这一片的原始字节。
- 除最后一片外,每片必须正好
part_size字节;请求必须带Content-Length。 - 不同分片可以乱序、并行上传;同一片失败后重传是安全的,新的一份替换旧的。
- 同一片不要同时传两份(上一次还没结束就重试),否则完成时会要求全部重传。
- 第 1 片会检查格式,必须是创建时声明的类型。
bearerAuthheader
授权Bearer <token>令牌(API Key),在控制台的令牌页复制,形如 sk-...。
upload_id*string创建分片上传时返回的 upload_id,原样放进路径。
part_number*integer片号,从 1 到 parts。
范围
1 <= valuebody*stringapplication/octet-stream这一片已保存。
application/json- response
part_number?integerbytes?integerFILE=ref.movAPI=https://tqai.org/v1/videos/references/uploadsAUTH="Authorization: Bearer $TQAI_API_KEY"SIZE=$(wc -c < "$FILE" | tr -d ' ')# 1. 创建(需要 jq)CREATED=$(curl -sS --fail "$API" -H "$AUTH" -H "Content-Type: application/json" \ -d "{\"content_type\":\"video/quicktime\",\"bytes\":$SIZE,\"filename\":\"$FILE\"}")UPLOAD_ID=$(echo "$CREATED" | jq -r .upload_id)PART_SIZE=$(echo "$CREATED" | jq -r .part_size)# 2. 按 part_size 切片,逐片上传;失败的分片可以原样重传split -b "$PART_SIZE" "$FILE" part_n=0for f in part_*; do n=$((n + 1)) curl -sS --fail --retry 3 --retry-all-errors -X PUT "$API/$UPLOAD_ID/parts/$n" -H "$AUTH" \ -H "Content-Type: application/octet-stream" --data-binary @"$f"donerm -f part_*# 3. 完成,拿到链接curl -sS --fail -X POST "$API/$UPLOAD_ID/complete" -H "$AUTH"示例响应
{ "part_number": 1, "bytes": 20971520}