I'm new to flutter and supabase. I am trying to list all files in a specific folder in a bucket.
In this example, namely folder '1'.
Future<List<FileObject>> fetchFilesFromFolder() async {
return await supabase
.storage
.from('public-images')
.list(path: folderId.toString()); // folderId is '1'
}
@override
Widget build(BuildContext context) {
final objects = fetchFilesFromFolder();
return FutureBuilder<List<FileObject>>(
future: objects,
builder: (context, snapshot) {
if (snapshot.hasData) {
final files = snapshot.data!;
print('FOLDER ID');
print(folderId);
print('Fetched objects:');
print(files);
...
The line print(files) prints out an empty list. Why is it not fetching the files?
I'd like to point us that getPublicUrl() works fine in the project, so I assume the Supabase set up should be fine?
final url1 = supabase.storage
.from('public-images')
.getPublicUrl('1/hackney1.jpeg');
For context, this is the content of the storage: Content of my supabase bucket
I'd really appreciate the help. Thank you!
.list()
requires select
RLS policy on your bucket even if it's a public bucket.
create policy "Public Access"
on storage.objects for select
using ( bucket_id = 'public-images' );