Uploads work, files 403? Fix Storage
You drop a photo into your upload field. The preview says it worked. On the live site the same file returns a blank image, a broken icon, or a 403 in the network panel. The upload request itself often still returns 200. What failed is reading the file back. Sites built with Lovable, Bolt, Replit, v0 or Cursor hit this a lot when they use Supabase Storage, or a similar object store, with policies never checked outside the builder's preview.
The symptom
- Uploads look successful, but the image or PDF never appears on the live page.
- The browser network tab shows
403,400or an empty body when loading the file URL. - It works for you while signed in, and fails for signed-out visitors (or the other way round).
- Old files still load; only new uploads after a policy or bucket change break.
- The public URL in the database looks right, but opening it in a private window fails.
The cause
Object storage separates writing a file from reading it. Your upload code can insert into a bucket while anonymous visitors, or even other signed-in users, have no select policy. Common causes:
- Private bucket, public URL. The code stores a
/object/public/...link, but the bucket is private, so the URL 403s for anyone not using a signed URL. - Missing Storage RLS. In Supabase,
storage.objectshas its own policies. Table RLS onprofilesorpostsdoes not cover files. An empty or too-tight select policy blocks reads. - Path / folder mismatch. Policies often allow only a folder equal to the user id. If the upload path uses a different folder, or none, inserts may still succeed while selects fail.
- Expired signed URLs. Short-lived signed links in emails or in the database expire. Cached pages keep serving the dead link.
- Wrong project on live. Preview points at one Supabase project; production env vars point at another with an empty or locked-down bucket.
Step-by-step diagnosis
- Open the file URL alone. Copy the exact
srcor href from the live page into a private window. Note the status code and body. - Compare signed-in vs signed-out. If it works only when you are logged in, you need a public read policy or a fresh signed URL for visitors.
- Check the bucket. In Supabase Storage, open the bucket: is it public? Confirm the object path exists.
- Read Storage policies. List select and insert rules on
storage.objects. Look forbucket_idfilters and anyauth.uid()path checks. - Diff preview and production keys. Confirm the live
SUPABASE_URLand anon key match the project where the file landed. - Watch the upload response. In DevTools, confirm the returned path matches the URL the page builds.
Fixes per builder or host
Supabase Storage (common with Lovable and Bolt)
Decide the access model first. For public assets (avatars, marketing images), make the bucket public and add a select policy that allows anon and authenticated to read that bucket_id. Keep insert limited to signed-in users, preferably under a folder named with their user id. For private files (invoices, ID scans), keep the bucket private and mint a signed URL at request time with a short expiry; never store a long-lived public URL for those.
Add policies in versioned SQL. A typical public-read rule checks bucket_id = 'avatars' on select; insert checks auth.role() = 'authenticated' plus a folder match. After changing policies, purge any CDN cache in front of the object URL.
Lovable and Bolt
Builders often create the bucket but leave policies empty or only set on the preview project. After you connect production Supabase, re-apply the same SQL there. Do not assume preview policies were copied. If the live site still uses a preview project URL in an env var, fix that first.
v0 / Cursor on Vercel, and Replit
Routes that mint signed URLs must use a server-only secret (the service role stays off the browser). Put it in production env vars on Vercel or Replit Deployments, redeploy, and call that route from the client. If the service role ever shipped to the browser, rotate it and move signing server-side.
Other object stores
On S3-compatible hosts, check the bucket policy and block-public-access settings the same way: upload permission is not read permission. Align the public base URL in your code with the bucket's real public endpoint.
How to verify
- Upload a new file while signed in, then open its URL in a private window with no session.
- Confirm a 200 and the expected content-type for public assets, or a working signed URL for private ones.
- Repeat from a phone off your Wi-Fi so you are not hitting a cached preview session.
- After a policy change, re-fetch with cache disabled and confirm old 403s are gone.
Prevention
- Keep Storage policies in versioned SQL next to the rest of your schema, and run them on every environment.
- Pick public-bucket vs signed-URL in the design, and never mix the two for the same folder.
- Add a smoke check after deploy: upload one file, then fetch it signed-out.
- Use separate Supabase projects for preview and production, with matching policy migrations.
