How can I force koa to use buffer in Strapi

27 Views Asked by At

I have a little issue with koa, I cannot get it to work sending buffer.

provided the following code:

const fooFunction = async (ctx: Context) => {
  ctx.response.set("Content-Type", "application/octet-stream");
  ctx.response.set(
    "Content-disposition",
    `attachment;filename=foo.bar`
  );
  ctx.body = {
    data: Buffer.from("test")
  }
  return ctx
}

The http request give me the following response:

{
  "data":{
    "type":"Buffer",
    "data":[116,101,115,116]
  }
}

If I change the object affected to body:

const fooFunction = async (ctx: Context) => {
  ctx.response.set("Content-Type", "application/octet-stream");
  ctx.response.set(
    "Content-disposition",
    `attachment;filename=foo.bar`
  );
  ctx.body = Buffer.from("test")
  return ctx
}

the http response contains

test

How can I force koa to send a response like

{
  "type":"Buffer",
  "data":[116,101,115,116]
}

Without wrapping it in an object ?

0

There are 0 best solutions below