Hey guys! TL;DR: Can you give me an advice for caching images from appwrite storages?
I am developing an App in Flutter. I want to fetch images from the appwrite storage. Currently i am using the suggested way to implement preview images like written here: https://appwrite.io/docs/client/storage?sdk=flutter-default#storageGetFileView But i would like to Cache them after i downloaded them once. I only found the plugin cached_network_image for that, but with that i have to add an header as my pictures are not public. (like here https://stackoverflow.com/questions/73770036/caching-images-thumbnails-in-listview ). But i really would like to avoid that and use as much from appwrites out-of-the-box-solutions as possible.
Current solution: return FutureBuilder( future: storage.getFileView( bucketId: BUCKET_IMAGES_ID, fileId: FILE_ID, ), builder: (context, snapshot) { return snapshot.hasData && snapshot.data != null ? Image.memory( snapshot.data, fit: BoxFit.cover, ) : snapshot.hasError ? Image.asset( "assets/images/testbild.jpg", fit: BoxFit.cover, ) : Image.asset( "assets/images/testbild.jpg", fit: BoxFit.cover, ); }, ); }
I think for local caching that's the only way in flutter
Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting
I'm pretty sure the network image widget automatically caches. You can use it by passing the file url. See https://github.com/appwrite/appwrite/discussions/3474#discussioncomment-3109355
I will try that tomorrow and give you an update. Thank you very much π
That worked perfectly with CachedNetworkImage as Image.Network was not really caching the data on my site. Could you give me an advice on how to check wether the JWT is still valid? I read that it is limited to 100 requests by every 60 minutes and i would love to check wether the actual JWT is still valid before creating a new one. Just to save your ressources. Thanks in advance!
I'm just creating a new one every time an user reaches the main page. Probably not the best approach, but in my case seems to be effective π€
Good idea. But I have an app with dashboard, events and blog entries. Every page contains pictures but unfortunetaly it is not completely safe that the user reaches the main page (dashboard) every 15 minutes, wich is the lifetime of the JWT.
Best way is to use it and make a network request. Otherwise, you can decode it and check the expiration
Thanks for your help! It worked well with CachedNetworkImage and therefore i will close this post π I will make a new one for getting information about how to get information about wether the JWT is still alive. Thank you!
[SOLVED] How to cache images from appwrite storages the proper way?
Recommended threads
- Our Appwrite organization is suspended
Please give support regarding this , no app is working now , please solve my issue and give support , no one is replying in message section or email.
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...