35

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

3 Answers 3

55

add new policy and enjoy :)

Because upsert need DELETE and UPDATE

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

This is terribly permissive, basically allowing auth'd users to do anything they want to the bucket to any folders.
@BradyDowling I agree that this dumbed-down example is, but in the SQL expression you can do far more, such as verifying the user authenticated's role, etc. Supabase is pretty powerful like that.
The image does not show...
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
  })

1 Comment

In Supabase i see it has 15kb all the uploaded pictures, how did you fix it?
1

I had the same problem! In Next.js the solution is to use "supabase" instance of auth-helpers ex: const supabase = createServerActionComponentClient({cookies}); instead of the normal supabase client created from key & url.

1 Comment

Could you share an example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.