# Binary file routing - headers settings

**URL:** <https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390>\
**Category:** Help me!\
**Created:** [April 28, 2021, 4:34pm UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390 "2021-04-28T16:34:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [April 28, 2021, 4:34pm UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/1 "2021-04-28T16:34:14Z")

</div>

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:

```javascript
{
    name: 'Générer un courrier',
    type: 'single',
    download: true,
}

```

In my route, it look like this :

```javascript
router.post('/actions/generer-un-courrier', permissionMiddlewareCreator.smartAction(), (request, response) => {
  const contract_id = request.body.data.attributes.ids[0];
  const body = {
    letter: {
      contract_id,
      letter_model_id: 1
    }
  };

  axios.post(`${API_URL}/forest_admin/letters`, body, {
    headers: {
      'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
      'X-CURRENT-USER-EMAIL': request.user.email,
    }
  }).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 });
    response.send(res.data);

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

```

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.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/0/068513857da61aad304890527fddd0b1324296b1.png)

---

<div class="post-metadata">

**Author:** ![anon79585656](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anon79585656](https://community.forestadmin.com/u/anon79585656)\
**Post date:** [April 29, 2021, 10:26am UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/2 "2021-04-29T10:26:28Z")

</div>

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 `axios.post` 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

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [May 3, 2021, 5:37pm UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/3 "2021-05-03T17:37:41Z")

</div>

Hello @anon79585656

Indeed this is a POST and not a GET :

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/8/89b06054f96ae9f66d52a7a9ceb380af57e6fcb6.png)

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.

---

<div class="post-metadata">

**Author:** ![morganperre](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/morganperre/32/1296_2.png) [@morganperre](https://community.forestadmin.com/u/morganperre)\
**Post date:** [May 4, 2021, 1:59pm UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/4 "2021-05-04T13:59:16Z")

</div>

Hey @JeremyV,

We have the following example with some static file.

[https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions#downloading-a-file](https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions#downloading-a-file)

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

Best regards,  
Morgan

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [May 5, 2021, 1:40pm UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/5 "2021-05-05T13:40:46Z")

</div>

More informations

This is an exemple of the file we are supposed to download :  
[blank\_letter\_so.tar](https://community.forestadmin.com/uploads/short-url/9Sk3FkJgVYp7fXW1D8waH94yfkL.tar) (15.5 KB)

This is what we get in FA :  
[blank\_letter\_so.tar](https://community.forestadmin.com/uploads/short-url/uhvJM6c7TN7gOlFCdJSKXg2DzFY.tar) (40 KB)

(files have been manually archived to be uploaded here)

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [May 6, 2021, 8:11am UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/6 "2021-05-06T08:11:02Z")

</div>

Hey @JeremyV, I’ll try to reproduce

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [May 6, 2021, 9:27am UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/7 "2021-05-06T09:27:33Z")

</div>

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

```javascript
async function downloadFromGet(request, response) {
  const requestResponse = await superagent.post(`${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');

  response.send(requestResponse.body);
}

```

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [June 1, 2021, 3:51pm UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/8 "2021-06-01T15:51:33Z")

</div>

Hi @morganperre @anon62739609  
Sorry I had to put this subject on the side for a few weeks.  
I managed to get an access for you to test from the real API.  
Can you provide an email address where I can share the Postman collection.

Thank you.

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [June 2, 2021, 7:35am UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/9 "2021-06-02T07:35:03Z")

</div>

Hey @JeremyV,  
As I say it works on our side so it must be coming from your code 😉. Did you try the code above ?

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [June 2, 2021, 8:29am UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/10 "2021-06-02T08:29:32Z")

</div>

Yes I did. no difference unfortunately. ☹

Here it is:

```javascript
router.post('/actions/generer-un-courrier', permissionMiddlewareCreator.smartAction(), async (request, response) => {
  const contract_id = request.body.data.attributes.ids[0];

  const body = {
    letter: {
      contract_id,
      letter_model_id: 1
  };

  const requestResponse = await axios.post(`${API_URL}/forest_admin/letters`, body, {
    headers: {
      'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
      'X-CURRENT-USER-EMAIL': request.user.email,
    }
  });

  response.setHeader('Content-Type', 'application/vnd.oasis.opendocument.text');
  response.setHeader('Content-Disposition', 'attachment; filename="blank_letter_so.odt"');
  response.setHeader('accept-ranges', 'bytes');
  response.setHeader('Access-Control-Expose-Headers', 'Content-Disposition');

  response.send(requestResponse.data);
});

```

i’ve got no other options…

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [June 3, 2021, 7:00am UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/11 "2021-06-03T07:00:35Z")

</div>

Weird. Could you try with `superagent` instead of `axios` ?  
If that’s still not that this mean the issue come from your url not returning the right format/data

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [July 7, 2021, 1:17pm UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/12 "2021-07-07T13:17:52Z")

</div>

The initial script is still not working. In the mean time I had another case which is basically the same phenomenon.

```javascript
router.post('/actions/courrier-changement-de-syndic-aux-fournisseurs', permissionMiddlewareCreator.smartAction(), (request, response) => {
  const maintenance_contract_ids = request.body.data.attributes.ids;

  models.maintenanceContracts.findOne({
    where: { id: maintenance_contract_ids[0] }
  }).then(maintenanceContract => {
    const place_id = maintenanceContract.placeIdKey;
    const body = {
      place_id,
      maintenance_contract_ids
    };

    axios.post(`${API_URL}/forest_admin/maintenance_contracts/send_new_management_info`, body, {
      headers: {
        'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
        'X-CURRENT-USER-EMAIL': request.user.email,
      }
    }).then(res => {
      response.setHeader('Content-Type', 'application/zip');
      response.setHeader('Content-Disposition', 'attachment; filename="Information de changement de syndic.zip"');
      response.setHeader('Access-Control-Expose-Headers', 'Content-Disposition');
      response.send(res.data);
    });
  });
});

```

In Postman, the zip file I get is 58 kB. In FA, the file I download is 107kB, and is corrupted.

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [July 7, 2021, 1:30pm UTC](https://community.forestadmin.com/t/binary-file-routing-headers-settings/2390/13 "2021-07-07T13:30:31Z")

</div>

Guys, just to let you know : it’s WORKING with `superagent`.

Don’t ask me why or how.
