Upload xlsx file to API

I’m trying to upload xlsx files to API using POST request. Here my code

let fileContent = open("./files.xlsx");

// Authorization
export function setup() {
  return {
    token: getToken(),

export default function (config) {
  const params = {
    headers: {
      Authorization: `Bearer ${config.token}`,
      "Content-Type": "application/octet-stream",

let url =
    baseUrl +

  var res = http.post(url, fileContent, params);

  check(res, {
    "Upload Excel 200": (res) => res.status === 200,

Unfortunatly it doesn’t work, i have this error “Cannot deserialize the current JSON object”. I have the same issue with postman.

Thanks you in advice for your help.

This is an error you see from the system you are testing, not from k6, right? Because I don’t think k6 emits such an error and I don’t see you doing anything with JSON in your script…

If so, then the only issue I can see with your script is the fact that you should probably open() the excel spreadsheet as a binary file, like this:

let fileContent = open("./files.xlsx", "b");

I’m not sure that this error is from k6. I already tried to open my excel spreadsheet as a binary files, and it doesn’t work either :confused:

Well, please paste the full error, with the stacktrace and all. Or a screenshot of the terminal window where you see it. This error string literally isn’t present in k6 and its dependencies or Go, but I can’t help you without more context and details…

Thank you for your help. I found my mistake. They send encoded base64 files. I didn’t realize it after a while