router-for-me/CLIProxyAPI · warning
failed to read uploaded file: %w
Error message
failed to read uploaded file: %w
What it means
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.
Source
Thrown at internal/api/handlers/management/auth_files_crud.go:253
}
func (h *Handler) storeUploadedAuthFile(ctx context.Context, file *multipart.FileHeader) (string, error) {
if file == nil {
return "", fmt.Errorf("no file uploaded")
}
name := filepath.Base(strings.TrimSpace(file.Filename))
if !strings.HasSuffix(strings.ToLower(name), ".json") {
return "", errAuthFileMustBeJSON
}
src, err := file.Open()
if err != nil {
return "", fmt.Errorf("failed to open uploaded file: %w", err)
}
defer src.Close()
data, err := io.ReadAll(src)
if err != nil {
return "", fmt.Errorf("failed to read uploaded file: %w", err)
}
if err := h.writeAuthFile(ctx, name, data); err != nil {
return "", err
}
return name, nil
}
func (h *Handler) writeAuthFile(ctx context.Context, name string, data []byte) error {
dst := filepath.Join(h.cfg.AuthDir, filepath.Base(name))
if !filepath.IsAbs(dst) {
if abs, errAbs := filepath.Abs(dst); errAbs == nil {
dst = abs
}
}
auth, err := h.buildAuthFromFileData(dst, data)
if err != nil {
return err
}View on GitHub (pinned to 78f0c4079e)
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.
Defensive patterns
Strategy: retry
Type guard
func isUploadReadFailure(err error) bool {
return err != nil && strings.Contains(err.Error(), "failed to read uploaded file")
} Try / catch
if isUploadReadFailure(err) {
err = uploadAgain(file) // client/server connection dropped mid-body
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Uploading over flaky networks; reverse proxies (nginx/traefik) with client_body_timeout shorter than slow uploads; mobile clients dropping connections.
Related errors
- no file uploaded
- failed to open uploaded file: %w
- failed to write file: %w
- auth path is empty
- Codex live request body too large
AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15).
Data as JSON: /api/errors/765dc6993f5b0845.
Report an issue: GitHub.