# addFileFromUrl() fails, is not found

**URL:** <https://community.fibery.io/t/addfilefromurl-fails-is-not-found/6639>\
**Category:** Bugs & Issues\
**Created:** [September 15, 2024, 4:36pm UTC](https://community.fibery.io/t/addfilefromurl-fails-is-not-found/6639 "2024-09-15T16:36:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![helloitse](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/helloitse/32/498_2.png) [@helloitse](https://community.fibery.io/u/helloitse)\
**Post date:** [September 15, 2024, 4:36pm UTC](https://community.fibery.io/t/addfilefromurl-fails-is-not-found/6639/1 "2024-09-15T16:36:16Z")

</div>

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:

```auto
        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](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/8/84e73c87a81a32e78526a14a35f2d81d135d9ece.png)

---

<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:** [September 15, 2024, 6:31pm UTC](https://community.fibery.io/t/addfilefromurl-fails-is-not-found/6639/2 "2024-09-15T18:31:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![helloitse](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/helloitse/32/498_2.png) [@helloitse](https://community.fibery.io/u/helloitse)\
**Post date:** [September 15, 2024, 11:18pm UTC](https://community.fibery.io/t/addfilefromurl-fails-is-not-found/6639/3 "2024-09-15T23:18:13Z")

</div>

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

---

<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:** [September 16, 2024, 5:15am UTC](https://community.fibery.io/t/addfilefromurl-fails-is-not-found/6639/4 "2024-09-16T05:15:03Z")

</div>

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

> [@helloitse](#):
>
> 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

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

> [@helloitse](#):
>
> it’s not possible to get the fileid/secret in the script

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

---

<div class="post-metadata">

**Author:** ![helloitse](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/helloitse/32/498_2.png) [@helloitse](https://community.fibery.io/u/helloitse)\
**Post date:** [September 16, 2024, 3:33pm UTC](https://community.fibery.io/t/addfilefromurl-fails-is-not-found/6639/5 "2024-09-16T15:33:15Z")

</div>

> [@Chr1sG](#):
>
> Yes, that is the purpose of the addFilesFromURL function.

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?

> [@Chr1sG](#):
>
> It’s possible to add extra lines to your script which will retrieve the secret(s) of any uploaded file(s)

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

---

<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:** [September 16, 2024, 4:43pm UTC](https://community.fibery.io/t/addfilefromurl-fails-is-not-found/6639/6 "2024-09-16T16:43:09Z")

</div>

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:

> [@helloitse](#):
>
> the error stopped when I created a Files field within the database

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

> [@helloitse](#):
>
> > [@Chr1sG](#):
> >
> > It’s possible to add extra lines to your script which will retrieve the secret(s) of any uploaded file(s)
> 
> I must have missed this in the docs. Could you share a link?

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

```auto
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']);
}

```
