responseType: "binary" returns an empty body

Hi there, Iā€™m trying to grab the binary response of an endpoint and then reuse the binary as a payload for subsequent request. However, when I try and obtain the body it seems empty.

As an example, I created the snippet below try to get publicly available binary from k6.io site

import http from "k6/http";

export default function () {
  let r = http.get(
    "https://k6.io/static/home-page-main-30c6e72806506138b9bd44a2ab31a419.mp4",
    { responseType: "binary" }
  );
  console.log("šŸš€ r.body =>", r.body);
  r = http.get(
    "https://k6.io/images/animations/home/any-scale/dashboard/img_0.svg",
    { responseType: "binary" }
  );
  console.log("šŸš€ r.body =>", r.body);
}

The output is this ā€¦

I also tried running with console-output

 k6 run --console-output "loadtest.log" .\script.js

That also returned nothing?

what am I doing wrong?

k6 v0.47.0 (commit/5ceb210056, go1.21.2, windows/amd64)

Hi @ryanrosello-og!

You did everything right. If you set responseType to binary, k6 returns the body as an ArrayBuffer. (Documentation at Params.responseType)
You can print its length with this: r.body.byteLength

1 Like

thanks, yeah that works

1 Like