admin管理员组

文章数量:1279207

I am trying to insert a file into a supabase public bucket, I've created basic policies to insert, select. when I try to upload a file though it returns

{
  statusCode: '401',
  error: 'Invalid JWT',
  message: 'new row violates row-level security policy for table "objects"'
}

I've coverted the file to base64 format then decoded the data during upload, could the error be anything related to this? I've tried adding multiple policies to the bucket but to no avail. My policies for bucket include public access policies for insert, select operations. policy : (bucket_id = 'trycoin'::text) is there any other policy I am supposed to add?

I am trying to insert a file into a supabase public bucket, I've created basic policies to insert, select. when I try to upload a file though it returns

{
  statusCode: '401',
  error: 'Invalid JWT',
  message: 'new row violates row-level security policy for table "objects"'
}

I've coverted the file to base64 format then decoded the data during upload, could the error be anything related to this? I've tried adding multiple policies to the bucket but to no avail. My policies for bucket include public access policies for insert, select operations. policy : (bucket_id = 'trycoin'::text) is there any other policy I am supposed to add?

Share Improve this question edited Jul 5, 2022 at 5:45 risky last asked Jul 4, 2022 at 20:09 risky lastrisky last 4756 silver badges20 bronze badges 4
  • Have you tried to create a public access policy to the bucket? – Mansueli Commented Jul 4, 2022 at 20:18
  • Yes I've tried doing that but it doesn't solve it either – risky last Commented Jul 4, 2022 at 20:24
  • Could you provide more details like source code, the policy you created or anything related? thanks. – Bo Lu Commented Jul 5, 2022 at 2:37
  • I did not create many policies just two policy for insert and select for bucket using (bucket_id = 'trycoin'::text) – risky last Commented Jul 5, 2022 at 5:46
Add a ment  | 

4 Answers 4

Reset to default 8

In order to be able to upload or download files from Supabase storage, you need to allow insert or select on the objects table and not the buckets table.

For example, if you want to allow upload(insert) in to the trycoin bucket, you could set a policy like this:

create policy "Allow upload on trycoin"
on storage.objects for insert
with check ( bucket_id = 'trycoin' );

You can find more examples on Supabase storage docs.

An option if you're just testing the file upload feature is disabling Row Level Security (RLS). To do this, follow these steps:

1). Goto table editor
2). Click on schema
3). Select the storage schema
4). Click the dropdown icon for the objects table
5). Click edit table
6). Uncheck Row Level Security (RLS)
7). And click save

Please be aware, Row Level Security (RLS) is remended for production apps to improve security.

You should also check if you spelled the bucketname correctly when trying to upload. It throws the same error in that case

I got the same error, so for me it was creating the right policy under storage.objects

I if you want to allow 'insert' for all, including non authenticated user, you can add a policy like this:

Example insert policy for all in storage.object

As dshukertjr mentioned, it is the best to check Supabase storage docs for more information.

本文标签: javascriptsupabase bucket policy to insert file not workingStack Overflow