grafana/k6 · error
invalid type %T, expected string or ArrayBuffer
Error message
invalid type %T, expected string or ArrayBuffer
What it means
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.
Source
Thrown at js/modules/k6/http/file.go:40
}
// File returns a FileData object.
func (mi *ModuleInstance) file(data any, args ...string) (*FileData, error) {
// supply valid default if filename and content-type are not specified
fname, ct := fmt.Sprintf("%d", time.Now().UnixNano()), "application/octet-stream"
if len(args) > 0 {
fname = args[0]
if len(args) > 1 {
ct = args[1]
}
}
switch data.(type) {
case string, sobek.ArrayBuffer:
default:
return nil, fmt.Errorf("invalid type %T, expected string or ArrayBuffer", data)
}
return &FileData{
Data: data,
Filename: fname,
ContentType: ct,
}, nil
}
View on GitHub (pinned to 01ffac6f24)
Solutions
- Pass file contents as a string (e.g. from open(...).read()) or an ArrayBuffer
- Example: http.file(open('./data.bin').read(), 'data.bin')
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at js/modules/k6/http/file.go:40 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/32d401b12243859f.
Report an issue: GitHub.