3

I am working with a project which needs to use python to store the jpg file into supabase storage. But I am getting an error:

Failed to upload file:
b'{"statusCode":"403","error":"Unauthorized","message":"new row violates row-level security policy"}'

I have set up the RLS policies in Supabase project and also given necessary permissions to Supabase Storage to upload files.

Here is my code:

file_path = r"C:\supabase projects\supabase auth 24-01-2024\uploads\test.jpg" file_name = "test.jpg" path_on_supastorage = "uploaded_files/test.jpg" content_type = "image/jpg" with open(file_path, 'rb') as file: response = supabase.storage.from_(bucket_name).upload( file=file, path=path_on_supastorage) # Check for successful upload if response is not None: print(f"Failed to upload file: {response.content}") else: print(f"File uploaded successfully: {response}") 

What is the cause of this problem exactly?

1
  • My hunch is that your policy is incorrect. See the docs here: supabase.com/docs/guides/storage/security/… Would be useful to update your question to include which policies you have created. Commented Feb 6, 2024 at 4:14

2 Answers 2

5

I had a similar issue and my first try was to switch to public. However, the fix is to leave it private and create a policy like the following: enter image description here

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

2 Comments

its not working... :(
Can you tell me more about your setup?
0

try

mime_type, _ = mimetypes.guess_type(file_path) response = supabase.storage.from_(bucket_name).upload( file=file, path=path_on_supastorage, file_options={ "headers" : { "content-type" : mime_type} }) 

this helped me

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.