not able to upload files to supabase storage bucket. this is the policy i have

((bucket_id = 'templates'::text) AND (storage.extension(name) = 'md'::text) AND (auth.role() = 'anon'::text)) when i try to upload files from dashboard, i get internal server error
27 Replies
garyaustin
garyaustin2y ago
Are you sure the policy is the issue? The dashboard should ignore the policy AND if bad policy you would get an RLS error. Check your storage and Postgres logs. Is this hosted or selfhosted/local?
shree
shreeOP2y ago
its on dashboard i dont think its dashboard issue i mean i dont think its policy issue i remove the policy i set the bucket to public it should have let me upload
garyaustin
garyaustin2y ago
Public does not allow uploads without meeting RLS policy. But the Dashboard storage UI should ignore it.
shree
shreeOP2y ago
No description
garyaustin
garyaustin2y ago
That is not an RLS policy error. Something is wrong.
shree
shreeOP2y ago
i tried to check logs. i dont see anything can you try creating a test storage bucket and see if you can upload
garyaustin
garyaustin2y ago
Internal server error should show an error in Storage or Postgres logs. Are you hosted?
shree
shreeOP2y ago
what do you mean hosted?
garyaustin
garyaustin2y ago
Are you using the Supabase online dashboard with their hosting or are you doing local dev or self hosting?
shree
shreeOP2y ago
online dashboard with their hosting
garyaustin
garyaustin2y ago
Please check the Postgres logs again.
garyaustin
garyaustin2y ago
No issues public or not for bucket.
No description
shree
shreeOP2y ago
No description
shree
shreeOP2y ago
no errors from logs oh i see an error null value in column "created_by" of relation "documents" violates not-null constraint this constraint i meant to apply on different bucket
garyaustin
garyaustin2y ago
You have triggers on storage.objects?
shree
shreeOP2y ago
yes
garyaustin
garyaustin2y ago
That can be very tricky. You can't just trigger on insert or update alone. This points out some of the issues....
shree
shreeOP2y ago
im trying see the trigger from dashboard for storage schea schema but not able to
garyaustin
garyaustin2y ago
No description
shree
shreeOP2y ago
yes how do you see the code for the trigger on dashboard create trigger on_file_upload after insert on storage.objects for each row execute procedure private.handle_storage_update();
garyaustin
garyaustin2y ago
You can't. Supabase does not let you generate code for triggers on their schemas. You have to use SQL editor. This is because most of the time you really need to know what you are doing and like last month the way they trigger changed.
shree
shreeOP2y ago
how do i add bucket name here
garyaustin
garyaustin2y ago
You can't just do an insert trigger see my link. There are two inserts for a file upload and probably a delete if the file can't be stored to s3 after the first one.
shree
shreeOP2y ago
thats okay. i do not care about number of times it gets invoked i just want it to trigger only on specific bucket
garyaustin
garyaustin2y ago
https://www.postgresql.org/docs/current/sql-createtrigger.html You would need to add a WHEN condition to check the bucket name column = 'name'.
PostgreSQL Documentation
CREATE TRIGGER
CREATE TRIGGER CREATE TRIGGER — define a new trigger Synopsis CREATE [ OR REPLACE ] [ CONSTRAINT ] TRIGGER name …
shree
shreeOP2y ago
thank you so much. i fixed it by checking the bucket id in the function >IF NEW.bucket_id <> 'my_bucket_name' THEN RETURN NEW; -- Exit the function if the bucket ID does not match END IF;

Did you find this page helpful?