file( data, [filename], [contentType] )
创建一个文件对象,用于构建Multipart 请求(文件上传)。
参数 | 类型 | 描述 |
---|---|---|
data | string / Array / ArrayBuffer | 文件数据,可以是字符串、数字数组或 ArrayBuffer 对象。 |
filename | string | 为此 multipart 请求的字段(或“部分”)指定的文件名。 |
contentType | string | 为此 multipart 请求的字段(或“部分”)指定的内容类型。 |
返回
类型 | 描述 |
---|---|
FileData | 一个 FileData 对象。 |
示例
import { sleep } from 'k6';
import { md5 } from 'k6/crypto';
import http from 'k6/http';
const binFile = open('/path/to/file.bin', 'b');
export default function () {
const f = http.file(binFile, 'test.bin');
console.log(md5(f.data, 'hex'));
console.log(f.filename);
console.log(f.content_type);
}