Is integration `fs.readFileSync` into k6 planned?

I didn’t find a way to use disk photos in k6 script? It is not possible for me to do it manually (convert each photo via base64). Thank you.

Hi @tpiksiades

Welcome to the community forum :wave:

Does open, loading a binary file, not work for your case? Can you provide an example and some more context of what you need to achieve?


Hello @eyeveebe
I need an image in base64 format as input in the request body, and the one in the screenshot doesn’t work for me. When I write response from fd.body() in console is empty object.
That is my first issue. And the second question is, can I use folder (with lot of photos) from my disc, instead just one file of photo? I have API define in another file. Thank you for helping me:)

Hi @tpiksiades FormData object doesn’t contain method body may return unknown method, Try using get methods from FormData object fd.get(‘images’) to concole value.
Second get uploads images as base64 you need convert from binary to base64 using k6 API encode

1 Like

Hi @tpiksiades

As @Elibarick already mentioned, you need to send a request (http.put,…), and we can’t see if you are. This can also help: Data Uploads

const fd = new FormData();
const res ='', fd.body(), {
    headers: { 'Content-Type': 'multipart/form-data; boundary=' + fd.boundary },

We don’t see what you do in the createCustomer() function and other calls. When sharing scripts, it’s easier if you can share in text form so we can copy&paste to reproduce. And add all the relevant data.

Another tool you can use to see what is going on is HTTP debugging, with a bit more detail in k6-learn. You will be able to see the response from the system under test, and why the status is not 200.

I hope this helps :bowing_woman:

1 Like

Hello @eyeveebe
Thanks for the reply, but I’m still confused. As input in body3 I need string base64 from image.jpg
But I had a response of 400, and it must be from incorrect converting, that I am dooing. I saw this b64encode( input, [encoding] ), but that not working for me. Buffer from image is very large… Could this be a problem? Or do I have another mistake?

const imageFile = open("../../fixture/image1.jpg", "b");
   const headers = {
    "Content-Type": "application/json",
    //"Content-Type": "multipart/form-data",
    Authorization: `Bearer ${token}`,
  const fd = new FormData();
  fd.append("photoDoc", http.file(imageFile, "image1.jpg", "image/jpeg"));
  const buf = new Uint8Array(fd).buffer;
  const encodedData = encoding.b64encode(buf);

  const urlCreateDocumentPage = `xxx/${idCustomer}/document/pages`;
  const body3 = {
    image: {
      data: encodedData,

  const res3 = http.put(urlCreateDocumentPage, body3, {
  check(res3, {
    "Create document page - Status is 200": (r) => r.status === 200,