TypeError: Object has no member 'readAll'

Hello everyone, I have some problems with the call to request a transfer of audio file, I hope someone can help me.
The error message is as follows:
Typeerror: Object has no member’ readAll’
it is a simple code instance using K 6version v0.43.1(K 6V0.43.1(2023-02-27T10:53:03 + 0000/v0.43.1-0-gaf3a0b89, GO 1.19.6, Linux/AMD64)
eg:

import http from 'k6/http';
import { check } from 'k6';
import { encode } from 'k6/encoding';
const audioFile = open('/root/tem/data/wav/11ec996590b7c32eac2ea000105020606000000059c65.wav', 'b'); //打开本地音频文件
const base64Data = encode(audioFile.readAll(), 'base64'); //将二进制数据转换为Base64编码

const url = 'http://example.com/upload-audio'; //替换为你的上传音频接口
audioFile.close(); //关闭文件句柄
const payload = JSON.stringify({ id: 1234, data: base64Data }); //设置请求体JSON格式,包含id和data参数

const headers = {
  headers: {
    'Content-Type': 'application/json',
  },
};
export default function () {
 

  const response = http.post(url, payload, headers); //发送HTTP请求

  check(response, {
    'status is 200': (r) => r.status === 200,
    'response body contains success message': (r) => r.body.includes('success'),
  });

   
}

I’m not sure what I might have done wrong. Has anyone had this problem before? If so, how did you handle it? I have uninstalled and reinstalled the latest version of K 6. Thank you for your help and advice. Thank you in advance!

Hi @wq5sw7w

I believe you encounter this error because what open returns is not a file handle as you seem to assume, but rather the file data themselves, as an ArrayBuffer. At the moment, the open function effectively behaves like a readAll function.

We have plans to address this in the future, but for now, you should be good be writing your code to this: const audioFile = open('/root/tem/data/wav/11ec996590b7c32eac2ea000105020606000000059c65.wav', 'b'); const base64Data = encode(audioFile, 'base64');

Let me know if that was helpful :bowing_man: