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

  1. Retry the upload on a stable connection.
  2. Raise reverse-proxy client body timeout / max body size if uploads are slow or large.
  3. Confirm the auth file is small and valid JSON before uploading (auth files are KB-scale).
  4. 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

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


AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15). Data as JSON: /api/errors/765dc6993f5b0845. Report an issue: GitHub.