英文:
list() returns no files when fetching from a folder in a Supabase storage bucket
问题
I'm new to flutter and supabase. I am trying to list all files in a specific folder in a bucket.
在这个例子中,特别是文件夹 '1'。
"print(files)" 这一行打印出一个空列表。为什么它没有获取文件?
我想指出 getPublicUrl() 在项目中运行正常,所以我假设 Supabase 的设置应该是正确的?
为了提供上下文,这是存储的内容:
我的 Supabase 存储桶的内容
我真的很感谢帮助。谢谢!
英文:
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!
答案1
得分: 1
.list()
需要在您的存储桶上使用select
RLS策略,即使它是一个公共存储桶。
create policy "Public Access"
on storage.objects for select
using ( bucket_id = 'public-images' );
英文:
.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' );
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论