9

i am having an issue with uploading avatars to my supabase bucket as its giving me "new row violates row-level security policy for table "objects"". I tried other StackOverflow solutions and nothing. Before trying to upload I log in using supabse so my user is authenticated yet its still not letting me upload. I added this policy in storage.objects:

(role() = 'authenticated'::text) and clicked the insert button. Does anyone know what I am doing wrong? I assume its something to do with the policies. Thanks

this is how I'm trying to upload my avatar:

try{
                const { data, error } = await supabase
                    .storage
                    .from('/public/avatars')
                    .upload(`${values.email}.png`, values.avatar, {
                        cacheControl: '3600',
                        upsert: true
                });
                if(error) throw error;
            }catch(error){
                console.log(error);
            }
Mat
  • 405
  • 4
  • 12

2 Answers2

15

add new policy and enjoy :)

Because upsert need DELETE and UPDATE

enter image description here

1

I'm guessing you have a bucket named public with a folder named avatars, correct?

In that case you would upload as follows:

const avatarFile = event.target.files[0]
const { data, error } = await supabase
  .storage
  .from('public')
  .upload(`avatars/avatar1.png`, avatarFile, {
    cacheControl: '3600',
    upsert: false
  })
thorwebdev
  • 818
  • 4
  • 9