yikart/AiToEarn · error · Error
上传视频失败,失败原因:获取上传id失败
Error message
上传视频失败,失败原因:获取上传id失败
What it means
During video upload, ShipinhaoService first requests an UploadID from the Tencent COS upload endpoint. If the response has no UploadID field, this error is thrown, meaning the initial upload-session request failed before any file bytes were sent.
Source
Thrown at project/aitoearn-electron/electron/plat/shipinhao/index.ts:682
const requestBody = {
BlockPartLength: filePartInfo.blockInfo,
BlockSum: filePartInfo.blockInfo.length,
};
const uploadIdRes = await this.uploadFile(
this.getApplyUploadDfsUrl,
Buffer.from(JSON.stringify(requestBody)),
{
Authorization: uploadParams.authKey,
'Content-Type': 'application/json',
'X-Arguments': uploadArgumentsString,
},
undefined,
proxy,
);
if (!uploadIdRes.UploadID) {
throw new Error('上传视频失败,失败原因:获取上传id失败');
}
const uploadId = uploadIdRes.UploadID;
const uploadPartInfo: any[] = [];
// 分片上传文件
for (let i = 0; i < filePartInfo.blockInfo.length; i++) {
let errorMsg = '';
const isSuccess = await RetryWhile(async () => {
if (this.callback)
this.callback(
50,
`上传视频(${i}/${filePartInfo.blockInfo.length})`,
);
console.log(
`开始上传第 ${i + 1}/${filePartInfo.blockInfo.length} 个分片`,
);
const chunkStart = i === 0 ? 0 : filePartInfo.blockInfo[i - 1];View on GitHub (pinned to d3aa8bea5b)
Solutions
- Re-fetch upload params via getPublishUploadParams with a fresh traceKey and retry.
- Validate the video file exists, is non-empty, and matches declared size before uploading.
- Log the full uploadIdRes payload — the server error field usually explains the rejection.
- Retry after a delay; COS throttling typically returns a temporary error without an UploadID.
Example fix
// before
if (!uploadIdRes.UploadID) {
throw new Error('上传视频失败,失败原因:获取上传id失败');
}
// after
if (!uploadIdRes.UploadID) {
console.error('applyUpload response:', JSON.stringify(uploadIdRes));
throw new Error(`上传视频失败,失败原因:获取上传id失败 ${JSON.stringify(uploadIdRes)}`);
} Defensive patterns
Strategy: validation
Validate before calling
import fs from 'fs';
const stat = fs.statSync(videoPath);
if (stat.size <= 0) throw new Error('video file is empty');
if (!uploadParams) throw new Error('upload params missing — refetch first'); Type guard
function hasUploadId(res: unknown): res is { UploadID: string } {
return typeof (res as any)?.UploadID === 'string' && (res as any).UploadID.length > 0;
} Try / catch
try {
const url = await service.uploadVideoFile(/*...*/);
} catch (e) {
if (e.message.includes('获取上传id失败')) {
// refetch upload params and retry the whole upload
}
} Prevention
- Validate the video file exists and is non-empty before uploading
- Always use freshly fetched upload params
- Log the full apply-upload response to capture COS error codes
- Add bounded retry with backoff for throttling
When it happens
Trigger: uploadVideoFile → the apply-upload (get upload id) request returns a payload without UploadID: invalid/expired upload params, wrong file size/hash fields, server throttling, or the response being an error page parsed as an object.
Common situations: Stale upload params from a failed getPublishUploadParams, video file too large or zero bytes, COS endpoint rejecting due to signature/param mismatch, or rate limiting on the upload API.
Related errors
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/a823ae63945be4f8.
Report an issue: GitHub.