grafana/k6 · error
copying file data to multipart form: %w
Error message
copying file data to multipart form: %w
What it means
Raised in newFileUploadRequest when io.Copy fails while streaming the artifact data reader into the multipart form's file part. This is a local read/write failure: the source reader errored mid-stream (e.g. upstream CDP stream aborted) or the in-memory form buffer write failed. No network upload has been attempted yet.
Source
Thrown at internal/js/modules/k6/browser/storage/file_persister.go:226
// we don't support multiple presigned URLs at the moment.
psu := resp.URLs[0]
// copy all form fields received from a presigned URL
// response to the multipart form fields.
var form bytes.Buffer
fw := multipart.NewWriter(&form)
for k, v := range psu.FormFields {
if err := fw.WriteField(k, v); err != nil {
return nil, fmt.Errorf("writing form field key %q and value %q: %w", k, v, err)
}
}
// attach the file data to the form.
ff, err := fw.CreateFormFile("file", psu.Name)
if err != nil {
return nil, fmt.Errorf("creating multipart form file: %w", err)
}
if _, err := io.Copy(ff, data); err != nil {
return nil, fmt.Errorf("copying file data to multipart form: %w", err)
}
if err := fw.Close(); err != nil {
return nil, fmt.Errorf("closing multipart form writer: %w", err)
}
req, err := http.NewRequestWithContext(
ctx,
psu.Method,
psu.PresignedURL,
&form,
)
if err != nil {
return nil, fmt.Errorf("creating new request: %w", err)
}
req.Header.Set("Content-Type", fw.FormDataContentType())
return req, nil
}View on GitHub (pinned to 01ffac6f24)
Solutions
- Verify the artifact data source is fully readable before persisting
- Retry the persist with a fresh data reader
- Check memory pressure — the multipart form is buffered in memory
- Inspect the wrapped error to identify reader vs writer failure
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/storage/file_persister.go:226 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/59df5d3ac218160b.
Report an issue: GitHub.