{"record":{"id":"32d401b12243859f","repo":"grafana/k6","slug":"invalid-type-t-expected-string-or-arraybuffer","errorCode":null,"errorMessage":"invalid type %T, expected string or ArrayBuffer","messagePattern":"invalid type %T, expected string or ArrayBuffer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"js/modules/k6/http/file.go","lineNumber":40,"sourceCode":"}\n\n// File returns a FileData object.\nfunc (mi *ModuleInstance) file(data any, args ...string) (*FileData, error) {\n\t// supply valid default if filename and content-type are not specified\n\tfname, ct := fmt.Sprintf(\"%d\", time.Now().UnixNano()), \"application/octet-stream\"\n\n\tif len(args) > 0 {\n\t\tfname = args[0]\n\n\t\tif len(args) > 1 {\n\t\t\tct = args[1]\n\t\t}\n\t}\n\n\tswitch data.(type) {\n\tcase string, sobek.ArrayBuffer:\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid type %T, expected string or ArrayBuffer\", data)\n\t}\n\n\treturn &FileData{\n\t\tData:        data,\n\t\tFilename:    fname,\n\t\tContentType: ct,\n\t}, nil\n}\n","sourceCodeStart":22,"sourceCodeEnd":49,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/js/modules/k6/http/file.go#L22-L49","documentation":"The http.file() helper only accepts string or sobek.ArrayBuffer as the data argument (anything else — object, number, null — hits the default case). It is a strict type validation on the first argument of http.file used to build multipart upload data.","triggerScenarios":"Thrown at js/modules/k6/http/file.go:40 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass file contents as a string (e.g. from open(...).read()) or an ArrayBuffer","Example: http.file(open('./data.bin').read(), 'data.bin')"],"exampleFix":null,"handlingStrategy":"type-guard","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"}