{"record":{"id":"35b6f849039b9da1","repo":"AlistGo/alist","slug":"resumable-upload-failed-with-status-d","errorCode":null,"errorMessage":"resumable upload failed with status %d","messagePattern":"resumable upload failed with status (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/mediafire/util.go","lineNumber":444,"sourceCode":"\t}\n\n\t//fmt.Printf(\"MediaFire resumable upload response (status %d): %s\\n\", res.StatusCode, string(body))\n\n\tvar uploadResp struct {\n\t\tResponse struct {\n\t\t\tDoupload struct {\n\t\t\t\tKey string `json:\"key\"`\n\t\t\t} `json:\"doupload\"`\n\t\t\tResult string `json:\"result\"`\n\t\t} `json:\"response\"`\n\t}\n\n\tif err := json.Unmarshal(body, &uploadResp); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to parse response: %v\", err)\n\t}\n\n\tif res.StatusCode != 200 {\n\t\treturn \"\", fmt.Errorf(\"resumable upload failed with status %d\", res.StatusCode)\n\t}\n\n\treturn uploadResp.Response.Doupload.Key, nil\n}\n\nfunc (d *Mediafire) uploadUnits(ctx context.Context, file *os.File, checkResp *MediafireCheckResponse, filename, fileHash, folderKey string, up driver.UpdateProgress) (string, error) {\n\tunitSize, _ := strconv.ParseInt(checkResp.Response.ResumableUpload.UnitSize, 10, 64)\n\tnumUnits, _ := strconv.Atoi(checkResp.Response.ResumableUpload.NumberOfUnits)\n\tuploadKey := checkResp.Response.ResumableUpload.UploadKey\n\n\tstringWords := checkResp.Response.ResumableUpload.Bitmap.Words\n\tintWords := make([]int, len(stringWords))\n\tfor i, word := range stringWords {\n\t\tintWords[i], _ = strconv.Atoi(word)\n\t}\n\n\tvar finalUploadKey string\n","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/mediafire/util.go#L426-L462","documentation":"The resumable upload unit POST returned an HTTP status other than 200. The body was already read and parsed (JSON unmarshal happens before this check), so the status is a definitive HTTP-level rejection: auth failure (401/403), bad request (400), rate limit (429), or server error (5xx). The key from the parsed body is not returned in this case.","triggerScenarios":"Expired action token or session producing 401; malformed unit headers or wrong Content-Range for 400; 429 from uploading units too fast; 5xx during MediaFire maintenance windows.","commonSituations":"Long uploads where the action token lapsed mid-transfer; parallel unit uploads tripping rate limits; unit boundary arithmetic off-by-one producing rejected requests; transient 502s behind MediaFire's CDN.","solutions":["Branch on the status: 401/403 → refresh session+action token then retry; 429 → backoff and slow the unit cadence; 5xx → retry with backoff; 400 → fix the request construction","Include the response body in the error message (it is already read) for precise diagnosis","Re-run uploadCheck if the upload key or bitmap state may have expired","For very large files, cap concurrent unit uploads and add per-request timeouts"],"exampleFix":"// before\nif res.StatusCode != 200 {\n    return \"\", fmt.Errorf(\"resumable upload failed with status %d\", res.StatusCode)\n}\n\n// after\nif res.StatusCode != 200 {\n    return \"\", fmt.Errorf(\"resumable upload failed with status %d: %.200s\", res.StatusCode, body)\n}","handlingStrategy":"retry","validationCode":"// Classify status before deciding to retry\nswitch {\ncase res.StatusCode == 401 || res.StatusCode == 403: refreshCreds()\ncase res.StatusCode == 429: return errRateLimited // backoff, do not fail\ncase res.StatusCode >= 500: return errTransient\n}","typeGuard":null,"tryCatchPattern":"// status-aware retry policy\nerr := d.resumableUpload(...)\nfor i := 0; i < 3 && isRetriableStatus(err); i++ {\n    if needsRelogin(err) { d.relogin() }\n    time.Sleep(backoff(i))\n    err = d.resumableUpload(...)\n}","preventionTips":["Branch retry policy on HTTP status rather than retrying everything","Include response body (already read) in status errors","Cap concurrent unit uploads to avoid 429s"],"tags":["mediafire","http-status","upload","go"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}