addFileFromUrl() fails, is not found

I’m currently working on a script to get website favicons and upload them to the Avatar collection.
In my script I have the following line:

        const fileResult = await fibery.addFileFromUrl(favicon, `favicon-${entity.id}.png`, entity.type, entity.id, {});

Which returns the following error. The function is defined in the scripting step documentation and validates inside the script block itself.
image

What is favicon ?
Is it a a valid URL for a file?

favicon is a constant containing the url. For testing purposes it is hardcoded. T
Example:
https://www.google.com/s2/favicons?domain=google.com&sz=64

A few notes here:
In troubleshooting, the error stopped when I created a Files field within the database. Which gives me the impression that addFileFromURL cannot add files to the avatars collection. The database I’m working with does not need a files field so I’ve since deleted it and

I also noticed that, when the function did run and upload images to the Files field, the success message returns the ID for the entity that triggers the script. So it’s not possible to get the fileid/secret in the script and then attach the file to the avatar field

[quote=“helloitse, post:3, topic:6639”]
addFileFromURL cannot add files to the avatars collection.
[/quote]

Yes, that is the purpose of the addFilesFromURL function: to add files to the Files field

It’s possible to add extra lines to your script which will retrieve the secret(s) of any uploaded file(s)

Well that’s the bug I think we have here. Are you able to successfully make an update on your end? If so, would you mind sharing an example of a script that works?

I must have missed this in the docs. Could you share a link?

Sorry that my previous answer was unclear.
When I wrote ‘Yes, that is the purpose of the addFilesFromUrl function’, I was writing in response to this:

In other words, yes, the addFilesFromUrl only serves to add a file to the files field.

There is no native function to upload a file to the avatar collection

Attached files can be retrieved in a similar way to any other entity:

const fibery = context.getService('fibery');

for (const entity of args.currentEntities) {
    const entityWithFiles = await fibery.getEntityById(entity.type, entity.id, ['Files']);
    const fileIDs = entityWithFiles['Files'].map((f) => f.Id);
    const files = await fibery.getEntitiesByIds('fibery/file', fileIDs, ['secret']);
}
1 Like