# Download all attachments via button

**URL:** <https://community.fibery.io/t/download-all-attachments-via-button/4133>\
**Category:** Get Help\
**Created:** [March 15, 2023, 7:25pm UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133 "2023-03-15T19:25:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eren\_Turgut](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/eren_turgut/32/4425_2.png) [@Eren\_Turgut](https://community.fibery.io/u/Eren_Turgut)\
**Post date:** [March 15, 2023, 7:25pm UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133/1 "2023-03-15T19:25:27Z")

</div>

Use case:  
After an invoice (database, with original PDF attached to entity) gets approved for payment, an additional PDF is generated within the entity which contains all necessary information for further processing (-\> single pager with summary of invoice information plus the approvals (date + person) and cost center).

I would like to quickly open the invoice + approval page of multiple approved invoices at one, with my system viewer (Adobe Reader Pro) and print it.

Is there anyone who could help in creating a script that would open all attached files of an entity with the default system program?

Trying to follow the api documentation:

```auto
const Fibery = require('fibery-unofficial');
const fibery = new Fibery({host: "YOUR_ACCOUNT.fibery.io", token: YOUR_TOKEN});

const files = await fibery.entity.query({
  'q/from': 'Cricket/Player',
  'q/select': [
    'fibery/id',
    { 'Files/Files': {
      'q/select': ['fibery/secret'],
      'q/limit': 'q/no-limit'
    } }
  ],
  'q/where': ['=', ['fibery/id'], '$entity-id'],
  'q/limit': 1
}, { '$entity-id': '20f9b920-9752-11e9-81b9-4363f716f666' });

```

> Grab the secrets:

```auto
[ { 'fibery/id': '20f9b920-9752-11e9-81b9-4363f716f666',
    'Files/Files': [
    { 'fibery/secret': 'a71a7f30-9991-11e9-b8d4-8aba22381101' },
    { 'fibery/secret': 'c5815fb0-997e-11e9-bcec-8fb5f642f8a5' } ] } ]

```

> Download Files using these secrets:

```auto
const Fibery = require('fibery-unofficial');
const fibery = new Fibery({host: "YOUR_ACCOUNT.fibery.io", token: YOUR_TOKEN});

await fibery.file.download('a71a7f30-9991-11e9-b8d4-8aba22381101', './playing.jpg');
await fibery.file.download('c5815fb0-997e-11e9-bcec-8fb5f642f8a5', './resting.jpg');

```

Am I correct to assume that:

- Cricket → Space, Player → Database
- I need to save the queried entity ID to a variable, which I use to query for the secret
- I need to save the secret to a variable to download the files using variable as placeholder of the secret in the example

Is there anyone who could help me with the code, or comment on my assumptions?

Thanks a lot in advance for any help!

---

<div class="post-metadata">

**Author:** ![tpaktop](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/tpaktop/32/6394_2.png) [@tpaktop](https://community.fibery.io/u/tpaktop)\
**Post date:** [March 16, 2023, 4:25am UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133/2 "2023-03-16T04:25:40Z")

</div>

> [@Eren\_Turgut](#):
>
> Cricket → Space, Player → Database

Yes that is correct.  
Syntax in fibery for all custom fields is `<Space>/<Database>`. Keep in mind that fields like id, and name are not custom.

> [@Eren\_Turgut](#):
>
> I need to save the queried entity ID to a variable, which I use to query for the secret  
> I need to save the secret to a variable to download the files using variable as placeholder of the secret in the example

to save an id in a variable you can use use `const` syntax.

```auto
const entityId = "20f9b920-9752-11e9-81b9-4363f716f666";

```

and later refer/use to it like this:

```auto
{ '$entity-id': entityId }

```

Make sure that const is declared before the place where you want to refer/use to it.

---

<div class="post-metadata">

**Author:** ![Viktar\_Zhuk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/viktar_zhuk/32/1934_2.png) [@Viktar\_Zhuk](https://community.fibery.io/u/Viktar_Zhuk)\
**Post date:** [March 16, 2023, 10:08am UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133/3 "2023-03-16T10:08:24Z")

</div>

Hi @Eren_Turgut

I’m not sure that get what you want achieve in your use case. Script written for a Button or Automation is running on server side sandbox and has no any connection with your Browser environment.

> script that would open all attached files of an entity with the default system program

So this one cannot be achieved.

---

<div class="post-metadata">

**Author:** ![Eren\_Turgut](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/eren_turgut/32/4425_2.png) [@Eren\_Turgut](https://community.fibery.io/u/Eren_Turgut)\
**Post date:** [March 16, 2023, 3:16pm UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133/4 "2023-03-16T15:16:05Z")

</div>

Thank you both for your help.

So I’ve tried to do it but getting an error message:

> **Download all files** is failed.  
> Failed to execute Action “Script”: Cannot read property ‘query’ of undefined

Can someone figure out which part is wrong? This is what my code looks like:

```auto
> const fibery = context.getService('fibery');
> const entityid1 = args.currentEntities[0].Id;
> 
> const files = await fibery.entity.query({
> 'q/from': 'Finance and Controlling/Invoice',
> 'q/select': [
> 'fibery/id',
> {
> 'Files/Files': {
> 'q/select': ['fibery/secret'],
> 'q/limit': 'q/no-limit'
> }
> }
> ],
> 'q/where': ['=', ['fibery/id'], '$entity-id'],
> 'q/limit': 1
> }, { '$entity-id': entityid1 });

```

I guess I have to query since the args.currentEntitites doesn’t include information on Files and their secrets, but can’t run this according to the API docs.

> [@Viktar\_Zhuk](#):
>
> I’m not sure that get what you want achieve in your use case. Script written for a Button or Automation is running on server side sandbox and has no any connection with your Browser environment.
> 
> > script that would open all attached files of an entity with the default system program
> 
> So this one cannot be achieved.

Hi @Viktar_Zhuk,

But it does send commands from the server side sandbox to my browser, no? And the browser has a connection to the browser environment?  
I guess the “open with system program” part could be set up within the browser settings, so just being able to download with the press of a button would be good enough.

---

<div class="post-metadata">

**Author:** ![Viktar\_Zhuk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/viktar_zhuk/32/1934_2.png) [@Viktar\_Zhuk](https://community.fibery.io/u/Viktar_Zhuk)\
**Post date:** [March 16, 2023, 4:00pm UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133/5 "2023-03-16T16:00:19Z")

</div>

> [@Eren\_Turgut](#):
>
> But it does send commands from the server side sandbox to my browser, no? And the browser has a connection to the browser environment?

No it works in completely different way. With this script you can interact with Fibery backend (e.g. pull data / update field value) and with other remote systems (pull, submit data). However you (or script) has no access to the Browser whatsoever.

You edit script which will be stored in some remote server.  
When you click a Button, UI sends requests to that remote server with some enumerated args and gets back simplistic success / error response.

Abilities you are talking about is not inherently impossible but not implement in any way atm.

---

<div class="post-metadata">

**Author:** ![Eren\_Turgut](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/eren_turgut/32/4425_2.png) [@Eren\_Turgut](https://community.fibery.io/u/Eren_Turgut)\
**Post date:** [March 16, 2023, 4:13pm UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133/6 "2023-03-16T16:13:16Z")

</div>

What I am asking for is a simple download of files:

- determine entity ID (done)
- determine secret for each file within said entity (failing to query for the secrets of files)
- download file via command: await fibery.file.download(secretID) for each secret.

Am I missing something here? There is a clear section on how to download, upload files and attach them to entitites (which I’m gonna use in a second step to copy File from one entity to the other).

But I can’t even run the simplest query:

> const users = await fibery.entity.query({  
> “q/from”: “Finance and Controlling/Invoice”,  
> “q/select”: [“fibery/id”],  
> “q/limit”: 1  
> });

which is supposed to give me the ID of 1 Invoice entity

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [March 16, 2023, 4:19pm UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133/7 "2023-03-16T16:19:53Z")

</div>

The examples at [api.fibery.io](http://api.fibery.io) are not intended to be used directly in automation scripts. It is intended for querying/manipulating data in a Fibery workspace using an external agent.

The guide for scripting is here: [. | Fibery](https://the.fibery.io/@public/User_Guide/Guide/Scripts-54)  
But as @Viktar_Zhuk said, scripting takes place on the server side, so it cannot push things to the browser.

---

<div class="post-metadata">

**Author:** ![Eren\_Turgut](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/eren_turgut/32/4425_2.png) [@Eren\_Turgut](https://community.fibery.io/u/Eren_Turgut)\
**Post date:** [March 16, 2023, 4:49pm UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133/8 "2023-03-16T16:49:08Z")

</div>

Ok thank you for the clarification.

It should however be possible to copy files to other entitites, as everything can happen server-side, no?

Use case:  
Invoices come in via email.  
Within the Email/Message database there is a button “Create invoice”, which prompts the user for some input (invoice date, number, amount, and so on) and then creates an entity in the Finance/Invoice database.

From my understanding of the backend, there is a separate storage for files, and each database utilizing files just gets another entity collection field, which basically references to that file via file’s ID and secret.

Now as we can’t leave the server environment, I guess what should be possible is to add an entity to the collection field (files) with the ID and Secret of an already existing file.

`executeSingleCommand(command: FiberyCommand)` might be needed for specific commands but I don’t see any reason to leave server environment for this to be possible, am I wrong here?

---

<div class="post-metadata">

**Author:** ![Viktar\_Zhuk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/viktar_zhuk/32/1934_2.png) [@Viktar\_Zhuk](https://community.fibery.io/u/Viktar_Zhuk)\
**Post date:** [March 16, 2023, 4:53pm UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133/9 "2023-03-16T16:53:00Z")

</div>

Please create a separate ticket for new enquiry to avoid any misunderstanding for other community members.

---

<div class="post-metadata">

**Author:** ![Eren\_Turgut](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/eren_turgut/32/4425_2.png) [@Eren\_Turgut](https://community.fibery.io/u/Eren_Turgut)\
**Post date:** [March 16, 2023, 5:02pm UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133/10 "2023-03-16T17:02:04Z")

</div>

Will do, thanks and sorry for the troubles.

---

<div class="post-metadata">

**Author:** ![mdubakov](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/mdubakov/32/10_2.png) [@mdubakov](https://community.fibery.io/u/mdubakov)\
**Post date:** [November 6, 2025, 2:31pm UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133/11 "2025-11-06T14:31:50Z")

</div>

Now Download all files is a native action in Batch Actions

> [@November 6, 2025 / Contributor Space access is being deprecated, Edit entities you create, Hide empty "No parent" groups](https://community.fibery.io/t/november-6-2025-contributor-space-access-is-being-deprecated-edit-entities-you-create-hide-empty-no-parent-groups/9967):
>
> Contributor Space access is being deprecated Now that we have a [new](https://community.fibery.io/t/october-30-2025-share-entities-to-web-using-access-templates-new-names-for-access-levels-improved-file-fields-support-in-automations/9924) beautiful (and consistent!) set of Space access levels, we will gradually deprecate the legacy Contributor access: Quick reminder: Contributors can see and comment on all entities in the Space as well as create new ones. Additionally, Contributors can edit entities they have created or are assigned to. Contributor access is an echo of dark times when you couldn’t [share a Database](https://the.fibery.io/@public/User_Guide/Guide/Share-Database-342) or [automatically share Entities with …](https://the.fibery.io/@public/User_Guide/Guide/Automatically-Share-Entities-with-assigned-People-327)

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [November 6, 2025, 3:16pm UTC](https://community.fibery.io/t/download-all-attachments-via-button/4133/12 "2025-11-06T15:16:10Z")

</div>


