Reputation: 724
I get this error while uploading files on Supabase storage, again Supabase storage not table :
new row violates row-level security policy
This is the code I am using in .NET:
internal sealed class StorageRepository : IStorageRepository
{
private readonly Client _client;
public StorageRepository(Client client)
{
_client = client;
}
public async Task<string> SaveFileAsync(
byte[] file,
string identifier,
string bucketName)
{
var result = await _client
.Storage
.From(bucketName)
.Upload(
data: file,
supabasePath: identifier);
return result;
}
}
This is complete error with detailed exception :
new row violates row-level security policy at Supabase.Storage.Extensions.HttpClientProgress.UploadAsync(HttpClient client, Uri uri, Stream stream, Dictionary`2 headers, Progress`1 progress) at Supabase.Storage.StorageFileApi.UploadOrUpdate(Byte[] data
I have tried by adding a new policy which allows only authenticated user to { SELECT, UPDATE, DELETE, UPDATE } but still it did not work:
Upvotes: 1
Views: 329
Reputation: 2872
A question regarding new row violates row-level security policy was asked by lucasmrl on Supabase's GitHub in 2021. lucasmrl answered their own question with some insight and a suggestion for how to handle the situation. Maybe that post can be useful?
To sum it up:
const { data, error } = await supabase.storage
.from("bucket ID")
.upload("file name", file, { cacheControl: "3600" });
"new row violates row-level security policy for table "objects"" statusCode: "42501"
Even if the bucket is "public", you still need to set up policies
To let people VIEW files in a bucket and UPLOAD files to a bucket, execute the following SQL queries:
VIEW: create
select
policy
create policy "Public Access Bucket Images Get"
on storage.objects for select
using ( bucket_id = 'bucket ID' );
UPLOAD: create
insert
policy
create policy "Public Access Bucket Images Post"
on storage.objects for insert
with check ( bucket_id = 'bucket ID' );
More on creating policies in Supabase in the docs.
Upvotes: 1