{"record":{"id":"c7ddc3151bb6e72d","repo":"AlistGo/alist","slug":"get-upload-token-failed-empty-task-id","errorCode":null,"errorMessage":"get upload token failed: empty task id","messagePattern":"get upload token failed: empty task id","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/guangyapan/driver.go","lineNumber":900,"sourceCode":"func (d *GuangYaPan) getUploadToken(ctx context.Context, parentID, name string, size int64) (*uploadTokenData, int, error) {\n\tvar out uploadTokenResp\n\terr := d.postAPI(ctx, \"/nd.bizuserres.s/v1/get_res_center_token\", map[string]any{\n\t\t\"capacity\": 2,\n\t\t\"name\":     name,\n\t\t\"parentId\": parentID,\n\t\t\"res\": map[string]any{\n\t\t\t\"fileSize\": size,\n\t\t},\n\t}, &out)\n\tif err != nil {\n\t\treturn nil, 0, err\n\t}\n\tmsg := strings.TrimSpace(out.Msg)\n\tif msg != \"\" && !strings.EqualFold(msg, \"success\") {\n\t\treturn nil, out.Code, fmt.Errorf(\"get upload token failed: %s\", msg)\n\t}\n\tif out.Data.TaskID == \"\" {\n\t\treturn nil, out.Code, errors.New(\"get upload token failed: empty task id\")\n\t}\n\tif out.Data.AccessKeyID == \"\" {\n\t\tout.Data.AccessKeyID = out.Data.Creds.AccessKeyID\n\t}\n\tif out.Data.SecretAccessKey == \"\" {\n\t\tout.Data.SecretAccessKey = out.Data.Creds.SecretAccessKey\n\t}\n\tif out.Data.SessionToken == \"\" {\n\t\tout.Data.SessionToken = out.Data.Creds.SessionToken\n\t}\n\tif strings.TrimSpace(out.Data.EndPoint) == \"\" {\n\t\tout.Data.EndPoint = strings.TrimSpace(out.Data.FullEndPoint)\n\t}\n\tif strings.TrimSpace(out.Data.EndPoint) != \"\" && !strings.HasPrefix(out.Data.EndPoint, \"http://\") && !strings.HasPrefix(out.Data.EndPoint, \"https://\") {\n\t\tif strings.TrimSpace(out.Data.FullEndPoint) != \"\" {\n\t\t\tout.Data.EndPoint = strings.TrimSpace(out.Data.FullEndPoint)\n\t\t} else if strings.TrimSpace(out.Data.BucketName) != \"\" {\n\t\t\thost := strings.TrimSpace(out.Data.EndPoint)","sourceCodeStart":882,"sourceCodeEnd":918,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/guangyapan/driver.go#L882-L918","documentation":"After POST to obtain an upload task the server replied with a success-ish message, but out.Data.TaskID is empty. The upload token exchange (fileSize included in the res map) is useless without a task id — the subsequent OSS-style credential fields (AccessKeyID/SessionToken/EndPoint fallbacks that follow) all belong to a task. The guard aborts before handing back unusable credentials.","triggerScenarios":"Upload-token endpoint returns msg=\"success\" (or empty) yet omits data.taskId. Seen with fileSize==0 uploads the backend silently rejects, response envelope drift (task id nested elsewhere), or a truncated success response from a rate-limited gateway.","commonSituations":"Attempting to upload a 0-byte file; provider API version bump renaming taskId; account out of quota so backend returns success-shaped body without creating a task.","solutions":["Log out.Code and the raw response body for the upload-token call to see what the server actually returned","Reject zero-byte uploads before calling getUploadToken; some backends refuse them with this shape","Verify the response struct in types.go matches the current API field names (taskId vs task_id casing via json tags)","Retry once — a transient gateway truncation can produce an empty data object"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if size <= 0 {\n\treturn nil, 0, errors.New(\"guangyapan upload requires a positive file size\")\n}","typeGuard":null,"tryCatchPattern":"token, code, err := d.getUploadToken(ctx, name, size)\nif err != nil && strings.Contains(err.Error(), \"empty task id\") {\n\t// server accepted but created no task: surface size/code for diagnosis\n\treturn fmt.Errorf(\"upload token rejected (size=%d code=%d): %w\", size, code, err)\n}","preventionTips":["Reject zero-byte uploads client-side before requesting an upload token","Pin and log the raw upload-token response in tests to catch API schema drift early"],"tags":["guangyapan","upload","api-contract","driver"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}