{"record":{"id":"7b928e67304e4114","repo":"AlistGo/alist","slug":"upload-failed-w","errorCode":null,"errorMessage":"upload failed: %w","messagePattern":"upload failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/darkibox/driver.go","lineNumber":258,"sourceCode":"\t\treturn nil, fmt.Errorf(\"no upload server URL returned\")\n\t}\n\n\t// Step 2: Upload the file to the upload server\n\treader := driver.NewLimitedUploadStream(ctx, &driver.ReaderUpdatingProgress{\n\t\tReader:         file,\n\t\tUpdateProgress: up,\n\t})\n\n\tres, err := base.RestyClient.R().\n\t\tSetContext(ctx).\n\t\tSetMultipartField(\"file\", file.GetName(), \"\", reader).\n\t\tSetMultipartFormData(map[string]string{\n\t\t\t\"key\":    d.APIKey,\n\t\t\t\"fld_id\": fldIDStr(folderID),\n\t\t}).\n\t\tPost(server.URL)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"upload failed: %w\", err)\n\t}\n\tif res.StatusCode() != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"upload failed: http %d\", res.StatusCode())\n\t}\n\n\t// Try to parse upload response to get the file code\n\tvar uploadResp uploadResult\n\tif err := base.RestyClient.JSONUnmarshal(res.Body(), &uploadResp); err == nil && len(uploadResp.Files) > 0 {\n\t\tuf := uploadResp.Files[0]\n\t\treturn &model.Object{\n\t\t\tID:       encodeFileID(uf.FileCode),\n\t\t\tName:     file.GetName(),\n\t\t\tSize:     file.GetSize(),\n\t\t\tIsFolder: false,\n\t\t}, nil\n\t}\n\n\treturn &model.Object{","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/darkibox/driver.go#L240-L276","documentation":"The multipart POST of the file bytes to the upload server URL failed at the transport level (%w wraps a resty/network error). This happens before any status-code check — the request never completed successfully: DNS failure, connection reset, TLS error, or context cancellation.","triggerScenarios":"resty Post() returns err on: context cancelled (user aborted upload), dial tcp timeout to the upload server host, TLS handshake failure, connection reset mid-transfer (often caused by the provider dropping large bodies), or reading from the limited stream erroring.","commonSituations":"Large uploads over unstable links; upload server host differs from apiBase and is blocked by firewall/GFW; proxy misconfiguration; user cancels the upload midway; disk read error while streaming the source file.","solutions":["If the wrapped error mentions context cancellation, the upload was aborted intentionally — not a bug","Retry the upload; resty-level transport errors are usually transient","Check connectivity to the specific upload server host returned by /upload/server (it may differ from the API domain)","For repeated resets on large files, verify MTU/proxy settings or try a smaller test file to isolate size-related drops"],"exampleFix":"// before\nres, err := base.RestyClient.R().\n\tSetContext(ctx).\n\tSetMultipartField(\"file\", file.GetName(), \"\", reader).\n\tPost(server.URL)\n// after — SetRetryCount/RetryCondition can be set on a dedicated client for transient transport errors\nres, err := base.RestyClient.R().\n\tSetContext(ctx).\n\tSetMultipartField(\"file\", file.GetName(), \"\", reader).\n\tPost(server.URL)\n// (wrap Put's caller with retry for \"upload failed: ... connection reset\" messages)","handlingStrategy":"retry","validationCode":"parsed, err := url.Parse(server.URL)\nif err != nil || parsed.Host == \"\" {\n\treturn nil, errors.New(\"upload server URL unusable\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"upload failed\") {\n\tif errors.Is(err, context.Canceled) { return err } // user abort: do not retry\n\treturn retryWithBackoff(ctx, upload, 3)\n}","preventionTips":["Use resumable/retryable upload wrappers for large files","Check egress to the upload host before big transfers","Abort cleanly on context cancellation instead of retrying"],"tags":["darkibox","upload","network","resty"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}