grafana/k6 · error
writing form field key %q and value %q: %w
Error message
writing form field key %q and value %q: %w
What it means
Raised in newFileUploadRequest when multipart.Writer.WriteField fails while copying a form field (key '%q', value '%q') received in the presigned-URL response into the multipart form buffer. The inputs at fault come from the remote service's FormFields map. Failure is a local encoding/buffer-write error — essentially only possible if a field value contains invalid UTF-8 that the multipart writer rejects.
Source
Thrown at internal/js/modules/k6/browser/storage/file_persister.go:217
}
// newFileUploadRequest creates a new HTTP request to upload a file as a multipart
// form to the presigned URL received from the server.
func newFileUploadRequest(
ctx context.Context,
resp PresignedURLResponse,
data io.Reader,
) (*http.Request, error) {
// 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,View on GitHub (pinned to 01ffac6f24)
Solutions
- Retry the persist to get a fresh presigned response with new form fields
- Report as a bug if the cloud service consistently returns problematic field values
- Verify no man-in-the-middle proxy is mangling the presigned response
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/storage/file_persister.go:217 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/05477e6d335303f9.
Report an issue: GitHub.