How to get all uploaded files of entity?

Hi there,
I have scenario to get all uploaded files of an entity and send public url of files to somewhere 3rd party for download. Let me know please how we can achieve it inside script.

Thanks

Do you mean you want a script that will send the URLs to a 3rd party?

Hi Niraj_Chourasia

Fibery platform could not provide you with public (not authorized) url to a file. To achieve that you have to implement own proxy or provide api key to 3rd party.

As I see, there is no helper method for file-url in script env.

So here is a snippet that prints direct urls to all Entity Files, please change your-acc.fibery.io to your account url

// Developer reference is at api.fibery.io/#action-buttons

// Fibery API is used to retrieve and update entities
const fibery = context.getService('fibery');

// affected entities are stored in args.currentEntities;
// to support batch actions they always come in an array
for (const entity of args.currentEntities) {
    // to get collection fields query the API and provide the list of fields
    const entityWithExtraFields = await fibery.getEntityById(entity.type, entity.id, ['Files']);

    for (const file of entityWithExtraFields.Files) {
        const fileWithSecret = await fibery.getEntityById("fibery/file", file.Id, ['secret']);
        console.log("https://" + "your-acc.fibery.io" + "/api/files/" + fileWithSecret.secret);
    }
    
}


// HTTP allows to send requests to external services
const http = context.getService('http');

/*
await http.postAsync('https://hooks.slack.com/services/YOUR_SLACK_URL', {
    body: {
        text: 'Successful success!'
    },
    headers: { 'Content-type': 'application/json' }
});
*/
3 Likes

No i want a script to get all attached files url of the current enity when user click on action button.

You can get URLs in the way suggested by @Viktar_Zhuk but access to the files requires authorisation.

even yes i need to send files to 3rd party

How i can provide authorisation for file?

It is an ordinary API call, you have to add Authorization header to HTTP request see download file api

curl -X GET https://YOUR_ACCOUNT.fibery.io/api/files/FILE_SECRET \
     -H 'Authorization: Token YOUR_TOKEN'
1 Like

Thank you it’s worked