Adding headers when sending a SSE with Buffer as a payload type (excel file download for client)

I have a custom actions which reading my database and converts the json response to an excel file.
Once the action is complete I want to send a SSE to my client browser with the buffer file as the payload.

What I am doing:

  channel: this.channelId,
  payload: buffer,

The buffer payload looks like this when I log it:

Is there a way to pass a header to the SSE with a content-type notifying the payload being an excel file for example?

Just like you would do with a node.js response:

var wbbuf = XLSX.write(wb, { type: 'buffer' });
res.writeHead(200, [['Content-Type',  'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']]);
res.end( wbbuf );

Never mind. I was able to deal with the payload on the client to download the excel file. Works like a charm.

1 Like