list() 从 Supabase 存储桶中获取文件夹时不返回任何文件。

huangapple go评论69阅读模式
英文:

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' );

huangapple
  • 本文由 发表于 2023年6月8日 16:18:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76429911.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定