Storage error: 403 Forbidden: 'new row violates row-level security policy' on upload
Last edited: 8/12/2026
如果你在上传文件时看到 403 Forbidden 错误,并且提示 'new row violates row-level security policy',通常意味着数据库无法返回新创建对象的元数据。即使你的 INSERT 策略定义正确并且用户的 JWT 有效,也可能会发生这种情况。
🌐 If you are observing a 403 Forbidden error with the message 'new row violates row-level security policy' when uploading files, it typically indicates that the database cannot return the metadata for the newly created object. This can happen even if your INSERT policies are correctly defined and the user's JWT is valid.
为什么会发生这种情况?
Supabase Storage API 会先执行一个 INSERT 操作,然后紧跟一个 RETURNING * 子句,以便向客户端返回对象详情。如果缺少 SELECT RLS 策略,或者策略没有覆盖正在上传的对象,数据库就无法返回行元数据。这会导致策略违规,从而使整个事务失败。
如何解决:
在 example_schema.example_table(具体是 storage.objects)上添加一个 SELECT RLS 策略,镜像你的 INSERT 要求。确保该策略允许认证用户读取自己当前正在创建的记录。
- 例如,如果你的 INSERT 策略仅限于
auth.uid(),那么你的 SELECT 策略也必须允许基于auth.uid()或特定存储桶和路径的访问。
你可以通过 仪表板 或 SQL 编辑器 管理你的 RLS 策略。
🌐 You can manage your RLS policies via the Dashboard or the SQL editor.