Reputation: 713
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);
}
Upvotes: 24
Views: 33071
Reputation: 11
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.
Upvotes: 1
Reputation: 961
add new policy and enjoy :)
Because upsert need DELETE and UPDATE
Upvotes: 43
Reputation: 1152
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
})
Upvotes: 1