Back

How to bundle assets with appwrite functions?

  • 1
  • Self Hosted
  • Functions
  • Flutter
  • Cloud
eldrigo
7 Jun, 2023, 08:15

I tried to bundle fonts with my appwrite function and used File('assets/font/open-sans.ttf').readAsByteSync() to access it in my functions code, but it errored with Error: FileSystemException: Cannot open file, path = 'assets/font/open-sans.ttf' (OS Error: No such file or directory, errno = 2) .

i used appwrite cli to deploy functions.

TL;DR
It seems like the user is trying to bundle assets with their appwrite functions, specifically in a Dart project. The user mentions that they compile the code into an executable and transfer that executable to the runtime container. They ask if there is a way to bundle assets into the executable and reference them. Another user suggests using Appwrite Storage as the best approach. One user mentions that every function in Appwrite is a Docker container, isolated from the outside world and without any persisted storage. They suggest using the Appwrite storage module to store and fetch assets when the function starts. Another user suggests uploading the assets to a CDN provider and using the links
safwan
7 Jun, 2023, 08:29

Not sure if you can bundle custom assets, but have you added the assets in the pubspec.yaml?

eldrigo
7 Jun, 2023, 08:31

Isn't assets in pubspec.yaml only available in flutter projects? This is a dart project

safwan
7 Jun, 2023, 08:33

To be honest, I'm not sure about plain dart. I've only used dart with flutter so far. Regardless, I'll try to find any documentation about assets in dart projects

safwan
7 Jun, 2023, 08:37

Can't seem to find anything so far, but have you tried using a URL for the assets?

So upload them on some CDN provider, and use the links to access them in your code.

eldrigo
7 Jun, 2023, 08:47

That would be another way, won't the files be uploaded when I deploy functions and have access to them via file system? Every function is a docker container, is it?

Binyamin
7 Jun, 2023, 13:09

Every function is a docker container, is it? Yes, it is. But its isolated from the outside world and don't have any persisted storage.

In case you do need to have some assets in your function and you unable to add them when you're deploying the function, Then, In this use case I will recommend to harnest the Appwrite storage module. and fetch the files from there when you function is statrting.

Drake
7 Jun, 2023, 17:28

For dart, we compile the code into an executable and only transfer that executable to the runtime container:

https://github.com/open-runtimes/open-runtimes/blob/801c6a833aec4ec72fc8562b5dffba2b3967ed6b/runtimes/dart-2.17/build.sh#L37

You could see if there's a way to bundle assets into an executable and see how to reference it

I do think using Appwrite Storage is the best approach, though.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more