Search code examples
javascriptnode.jsfile-uploadsupabase

supabase bucket policy to insert file not working


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?


Solution

  • 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.