{"record":{"id":"765dc6993f5b0845","repo":"router-for-me/CLIProxyAPI","slug":"failed-to-read-uploaded-file-w","errorCode":null,"errorMessage":"failed to read uploaded file: %w","messagePattern":"failed to read uploaded file: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"warning","filePath":"internal/api/handlers/management/auth_files_crud.go","lineNumber":253,"sourceCode":"}\n\nfunc (h *Handler) storeUploadedAuthFile(ctx context.Context, file *multipart.FileHeader) (string, error) {\n\tif file == nil {\n\t\treturn \"\", fmt.Errorf(\"no file uploaded\")\n\t}\n\tname := filepath.Base(strings.TrimSpace(file.Filename))\n\tif !strings.HasSuffix(strings.ToLower(name), \".json\") {\n\t\treturn \"\", errAuthFileMustBeJSON\n\t}\n\tsrc, err := file.Open()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to open uploaded file: %w\", err)\n\t}\n\tdefer src.Close()\n\n\tdata, err := io.ReadAll(src)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to read uploaded file: %w\", err)\n\t}\n\tif err := h.writeAuthFile(ctx, name, data); err != nil {\n\t\treturn \"\", err\n\t}\n\treturn name, nil\n}\n\nfunc (h *Handler) writeAuthFile(ctx context.Context, name string, data []byte) error {\n\tdst := filepath.Join(h.cfg.AuthDir, filepath.Base(name))\n\tif !filepath.IsAbs(dst) {\n\t\tif abs, errAbs := filepath.Abs(dst); errAbs == nil {\n\t\t\tdst = abs\n\t\t}\n\t}\n\tauth, err := h.buildAuthFromFileData(dst, data)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/api/handlers/management/auth_files_crud.go#L235-L271","documentation":"storeUploadedAuthFile reads the opened multipart part into memory with io.ReadAll; any read failure produces `failed to read uploaded file: %w`. This happens when the connection is interrupted mid-body or the part's backing storage errors during read — the upload started correctly but the bytes did not arrive intact.","triggerScenarios":"Client disconnect/abort partway through the multipart body; network reset (proxy timeout, LB idle kill) during upload; the multipart part's temp backing file removed while reading; client-side timeouts truncating the request.","commonSituations":"Uploading over flaky networks; reverse proxies (nginx/traefik) with client_body_timeout shorter than slow uploads; mobile clients dropping connections.","solutions":["Retry the upload on a stable connection.","Raise reverse-proxy client body timeout / max body size if uploads are slow or large.","Confirm the auth file is small and valid JSON before uploading (auth files are KB-scale).","Check server logs for simultaneous network resets around the failure."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"func isUploadReadFailure(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"failed to read uploaded file\")\n}","tryCatchPattern":"if isUploadReadFailure(err) {\n    err = uploadAgain(file) // client/server connection dropped mid-body\n}","preventionTips":["Raise reverse-proxy client_body_timeout for slow uploads.","Upload over stable connections; verify JSON file size before sending.","Retry once before investigating — mid-body disconnects are usually transient."],"tags":["management-api","upload","network"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}