Binary file routing - headers settings

I’ve been struggling with this for a while now.

I have a smart action which purpose is to download a pre-filled odt file:

    name: 'Générer un courrier',
    type: 'single',
    download: true,

In my route, it look like this :'/actions/generer-un-courrier', permissionMiddlewareCreator.smartAction(), (request, response) => {
  const contract_id =[0];
  const body = {
    letter: {
      letter_model_id: 1
  };`${API_URL}/forest_admin/letters`, body, {
    headers: {
      'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
  }).then(res => {

    // response.setHeader('Content-Type', 'application/vnd.oasis.opendocument.text');
    // response.setHeader('Transfer-Encoding', 'chunked');
    // // response.setHeader('Connection', 'keep-alive');
    // response.setHeader('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
    // response.setHeader('Access-Control-Expose-Headers', 'Content-Disposition');
    // response.setHeader('Content-Disposition', 'attachment; filename="blank_letter_so.odt"');
    // response.setHeader('Content-Transfer-Encoding', 'binary');

    // response.set({ ...res.headers });

  }).catch(err => {
    response.status(400).send({ error: });

My API provider is sending me a binary odt file which I’d like to send back to Forest Admin.

I have tried basically all combinations of headers settings before send() (all the comments above). At the very best, I receive a corrupted unreadable file. I’ve been trying to copy the response headers as well : response.set({ ...res.headers });

I’m clearly missing something here, all I want to do is transfer my binary file to my FA front-end.

Note that everything is working fine in Postman.

Hello @JeremyV,

Just to be sure, do you need your Axios call to be a POST and not a GET?
I tried to create a simple file server locally (with the http-server nom package), and if I change to axios.get in you code sample (and adapt the file URL of course) I can receive a file via my Forest Admin panel.

If changing the post to get is not right, could you tell me what api provider your are using? If they provide a free account I could try to reproduce you issue.

Thank you

Hello @Guillaume_Deslandes

Indeed this is a POST and not a GET :

It might be quite difficult to allow you to test this API since this is in a private domain accessible through VPN… I’ll see what I can do.

Hey @JeremyV,

We have the following example with some static file.

But, we don’t have any example with your use case. I’ll try to reproduce your issue.

Best regards,

More informations

This is an exemple of the file we are supposed to download :
blank_letter_so.tar (15.5 KB)

This is what we get in FA :
blank_letter_so.tar (40 KB)

(files have been manually archived to be uploaded here)

Hey @JeremyV, I’ll try to reproduce

I just tried and I had no issue. I have the following code:

async function downloadFromGet(request, response) {
  const requestResponse = await`${process.env.API_URL}/download-odt`);

  response.setHeader('content-type', 'application/vnd.oasis.opendocument.text');
  response.setHeader('content-disposition', 'attachment; filename="blank_letter_so.odt"');
  response.setHeader('accept-ranges', 'bytes');

1 Like