{"record":{"id":"59df5d3ac218160b","repo":"grafana/k6","slug":"copying-file-data-to-multipart-form-w","errorCode":null,"errorMessage":"copying file data to multipart form: %w","messagePattern":"copying file data to multipart form: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/storage/file_persister.go","lineNumber":226,"sourceCode":"\t// we don't support multiple presigned URLs at the moment.\n\tpsu := resp.URLs[0]\n\n\t// copy all form fields received from a presigned URL\n\t// response to the multipart form fields.\n\tvar form bytes.Buffer\n\tfw := multipart.NewWriter(&form)\n\tfor k, v := range psu.FormFields {\n\t\tif err := fw.WriteField(k, v); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"writing form field key %q and value %q: %w\", k, v, err)\n\t\t}\n\t}\n\t// attach the file data to the form.\n\tff, err := fw.CreateFormFile(\"file\", psu.Name)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating multipart form file: %w\", err)\n\t}\n\tif _, err := io.Copy(ff, data); err != nil {\n\t\treturn nil, fmt.Errorf(\"copying file data to multipart form: %w\", err)\n\t}\n\tif err := fw.Close(); err != nil {\n\t\treturn nil, fmt.Errorf(\"closing multipart form writer: %w\", err)\n\t}\n\n\treq, err := http.NewRequestWithContext(\n\t\tctx,\n\t\tpsu.Method,\n\t\tpsu.PresignedURL,\n\t\t&form,\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating new request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", fw.FormDataContentType())\n\n\treturn req, nil\n}","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/storage/file_persister.go#L208-L244","documentation":"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.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/storage/file_persister.go:226 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}