Send audio file (wav) with k6 in POST request

Hi,

As part of my test in K6, I need to send a wav (audio) file to the server in POST request. The audio file should be first converted/encoded to base64.

I tried this code:

import encoding from 'k6/encoding'

const audioFile = open('test-data/sample_20240529.wav', 'b');
const data = encoding.b64decode(audioFile, 'std', 's')

but I’m getting this error:

ERRO[0001] GoError: illegal base64 data at input byte 0
        at go.k6.io/k6/js/modules/k6/encoding.(*Encoding).b64Decode-fm (native)

The audio file is fine, and I was able to convert it manually(using one of the available sites on the net, such as: Audio to Base64 | Base64 Encode | Base64 Converter | Base64) to base64 and sent it successfully to the server, but I’m looking for a way to make the convention (from audio to base64) in code.

Any suggestions will be highly appreciated!

Thanks,
Ido

Hi @idolevi, welcome to the community forum!

You should use b64encode function instead of b64decode

I hope it helps

1 Like

Thank you! That solved my issue

1 Like