{"record":{"id":"8baeaffbe9d65e58","repo":"grafana/k6","slug":"creating-multipart-form-file-w","errorCode":null,"errorMessage":"creating multipart form file: %w","messagePattern":"creating multipart form file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/storage/file_persister.go","lineNumber":223,"sourceCode":"\tresp PresignedURLResponse,\n\tdata io.Reader,\n) (*http.Request, error) {\n\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())","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/storage/file_persister.go#L205-L241","documentation":"Raised in newFileUploadRequest when fw.CreateFormFile('file', psu.Name) fails to create the file part header of the multipart form. The input at fault is psu.Name, the file name supplied by the presigned-URL response. CreateFormFile rejects names containing '\\r' or '\\n' (header injection guard), so this fires when the remote service returns a file name with embedded newline characters.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/storage/file_persister.go:223 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the persist; a fresh presigned response will carry a new file name","Report to k6 Cloud support if file names are consistently malformed","Check whether custom artifact names/options introduce newline characters"],"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"}