Supabase Storage Upload Error— Permission Denied & More [Fixed 2026]
Also covers: bucket creation · storage RLS policies · file size limits · public URL · Server Action uploads
⚡ Common Errors
{ statusCode: "403", error: "Unauthorized", message: "new row violates row-level security policy" }
// OR:
{ statusCode: "404", error: "Bucket not found" }
// OR:
{ statusCode: "413", error: "Payload Too Large" }✅ Basic working upload pattern
const { data, error } = await supabase.storage
.from("avatars") // bucket name
.upload(`${userId}/avatar.png`, file, {
upsert: true, // overwrite if exists
contentType: "image/png",
})
if (error) console.error(error.message)
// Get public URL (public bucket only)
const { data: { publicUrl } } = supabase.storage
.from("avatars")
.getPublicUrl(`${userId}/avatar.png`)Why Supabase Storage Uploads Fail
Storage errors have three main categories: permissions (RLS blocking the upload), configuration (bucket doesn't exist, wrong name, file too large), or code mistakes (wrong path in getPublicUrl, missing upsert flag on re-upload). Most errors are permissions-related.
Create the Bucket and Set Access Policy
Bucket not found OR all uploads fail# Dashboard: Storage → New bucket
Bucket name: avatars (no spaces, lowercase)
Public bucket: ✅ (toggle ON for images shown to users)
File size limit: 5 MB (adjust as needed)
Allowed MIME types: image/* (optional — leave blank for all types)
# OR via SQL:
INSERT INTO storage.buckets (id, name, public, file_size_limit, allowed_mime_types)
VALUES (
'avatars',
'avatars',
true,
5242880, -- 5MB in bytes
ARRAY['image/jpeg', 'image/png', 'image/webp', 'image/gif']
);Add Storage RLS Policies for Upload
403 Unauthorized on upload — most common fixStorage uses RLS on the storage.objects table. For private buckets, you must add policies for INSERT (upload), SELECT (read), and DELETE.
-- Allow authenticated users to upload to their own folder
CREATE POLICY "Users upload own files"
ON storage.objects FOR INSERT
TO authenticated
WITH CHECK (
bucket_id = 'avatars'
AND auth.uid()::text = (storage.foldername(name))[1]
);
-- File path must be: {user-uuid}/filename.ext
-- Allow authenticated users to read their own files
CREATE POLICY "Users read own files"
ON storage.objects FOR SELECT
TO authenticated
USING (
bucket_id = 'avatars'
AND auth.uid()::text = (storage.foldername(name))[1]
);
-- Allow users to delete their own files
CREATE POLICY "Users delete own files"
ON storage.objects FOR DELETE
TO authenticated
USING (
bucket_id = 'avatars'
AND auth.uid()::text = (storage.foldername(name))[1]
);
-- For PUBLIC bucket — allow anyone to read (no auth needed)
CREATE POLICY "Public read avatars"
ON storage.objects FOR SELECT
TO anon, authenticated
USING (bucket_id = 'avatars');Fix File Size and MIME Type Limits
413 Payload Too Large or unsupported file type-- Increase file size limit (in bytes)
UPDATE storage.buckets
SET file_size_limit = 52428800 -- 50MB
WHERE id = 'documents';
-- Update allowed MIME types
UPDATE storage.buckets
SET allowed_mime_types = ARRAY[
'image/jpeg', 'image/png', 'image/webp',
'application/pdf',
'video/mp4'
]
WHERE id = 'uploads';
-- Validate file size client-side before uploading
const MAX_SIZE = 5 * 1024 * 1024 // 5MB
if (file.size > MAX_SIZE) {
alert("File must be under 5MB")
return
}Get the Correct Public URL After Upload
Object not found or URL returns 404The path in getPublicUrl must exactly match the path used during upload, including any folder prefix. For private buckets, use createSignedUrl instead.
async function uploadAvatar(userId: string, file: File) {
const filePath = `${userId}/${Date.now()}-${file.name}`
// Upload the file
const { error: uploadError } = await supabase.storage
.from("avatars")
.upload(filePath, file, { upsert: true })
if (uploadError) throw uploadError
// Get public URL (public bucket)
const { data: { publicUrl } } = supabase.storage
.from("avatars")
.getPublicUrl(filePath) // ← same path as upload
return publicUrl
// For PRIVATE bucket — use signed URL instead:
// const { data, error } = await supabase.storage
// .from("documents")
// .createSignedUrl(filePath, 60 * 60) // expires in 1 hour
// return data?.signedUrl
}Upload Files from Next.js Server Actions
File uploads handled on the serverRead the file from FormData in a Server Action, then upload using the Supabase server client. Use the admin client to bypass storage RLS for server-side uploads.
"use server"
import { createClient } from "@/lib/supabase/server"
export async function uploadAvatar(formData: FormData) {
const file = formData.get("avatar") as File
if (!file || file.size === 0) return { error: "No file provided" }
const supabase = await createClient()
const { data: { user } } = await supabase.auth.getUser()
if (!user) return { error: "Not authenticated" }
// Read file as ArrayBuffer
const arrayBuffer = await file.arrayBuffer()
const filePath = `${user.id}/${Date.now()}-${file.name}`
const { error } = await supabase.storage
.from("avatars")
.upload(filePath, arrayBuffer, {
contentType: file.type,
upsert: true,
})
if (error) return { error: error.message }
const { data: { publicUrl } } = supabase.storage
.from("avatars")
.getPublicUrl(filePath)
// Save URL to user profile
await supabase
.from("profiles")
.update({ avatar_url: publicUrl })
.eq("id", user.id)
return { publicUrl }
}Prevention
- Create the bucket before writing upload code — verify bucket name exactly matches your code
- Toggle 'Public bucket' ON for images and assets shown to all users — no RLS needed for reads
- Add storage INSERT and SELECT RLS policies for private buckets before testing
- Use the file path format {user-id}/filename so storage.foldername() policies work correctly
- Validate file size and MIME type client-side before calling upload — better UX than a 413 error
- Use the same filePath variable for both upload() and getPublicUrl() to avoid URL mismatches
Frequently Asked Questions
Why does Supabase Storage return 'permission denied'?+−
What is the difference between a public and private Supabase bucket?+−
What is the Supabase Storage file size limit?+−
How do I get the public URL of an uploaded file in Supabase?+−
Can I upload files from a Next.js Server Action?+−
Why does my uploaded file show 'Object not found' when I try to access it?+−
Need Expert Help?
We Build File Upload Pipelines with Supabase
Softplix engineers implement Supabase Storage for avatars, documents, and media — with RLS, signed URLs, and image optimisation. Let us help.
Talk to an Engineer