Back

[SOLVED] How to get an asset image in a Dart Function?

  • 0
  • Functions
djcali
12 Apr, 2023, 05:32

Hi, I need to access an image file in my dart function. The file is in the lib folder just like the main.dart but all the paths I have tried didn't work like lib/image.png or just image.png. Any ideas? Thanks

I am sending an email with an attachment, the mailer package says to use File('/path/to/file') but the image is never included in the emails that get sent.

TL;DR
User is looking for a way to access an asset image in a Dart function. There are suggestions to try using File('lib/file.png'), but it does not work. User is advised that the assets feature is specific to Flutter and may not be available in a Dart app. A reference to the Appwrite documentation is provided. User confirms using Appwrite storage as an option. User considers using node mailer instead but prefers Dart. User prints the default directory path and discovers it to be "/usr/code-start". User wonders if there is a way to reference a file outside of the main.dart. Another user mentions that assets are for Flutter.
joeyouss
12 Apr, 2023, 06:43

Hi - it needs to be in assets as made compulsory by Flutter, adding some source codes for reference: https://github.com/appwrite/awesome-appwrite#flutter

djcali
12 Apr, 2023, 13:57

Hi. Thanks for the references but I can't seem to find what I'm looking for. Is there a specific example using a Dart function to access an asset? Thanks.

joeyouss
12 Apr, 2023, 14:03

lemme check once

Drake
12 Apr, 2023, 17:54

that assets stuff is for Flutter...I'm not even sure if you can have assets in a dart app...

djcali
12 Apr, 2023, 18:00

oh ok. There has to be a way in dart to reference a file outside of the main.dart. I tried using File('lib/file.png') noting works. I guess because the path changes after the Function gets compiled?

djcali
12 Apr, 2023, 18:03

I did a print statement in the code print(Directory.default.path) and after i looked at the execution logs i got back /usr/code-start

Drake
12 Apr, 2023, 18:09

yes, we also compile the code and only move the executable over to the final runtime container for execution

djcali
12 Apr, 2023, 18:11

Ok. Might just have to use node mailer instead. I just am way more comfortable with dart. 😟

Drake
12 Apr, 2023, 18:12

maybe store your file in Appwrite storage?

djcali
12 Apr, 2023, 18:13

Yes. That is an option also, and just reference the file from there.

djcali
12 Apr, 2023, 18:21

Made it work using that method. Thanks.

djcali
12 Apr, 2023, 18:21

[SOLVED] How to get an asset image in a Dart Function?

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