
Mini lesson · English
How to let users upload images
Upload, reopen and delete supplied test images while checking size limits and account ownership.
Who is this for?
People who want visitors to upload images. You can use the ready project and a coding assistant without writing storage policies or upload code.
Before you start
A separate Supabase practice project with two controlled test accounts. The small, oversized and unsupported files are supplied. Ask the assistant to prepare the private avatars storage and provided policies in this disposable project.
Estimated time: 25–42 min
Estimates for the supplied starter files with prerequisite accounts and tools ready. Setup, deployment queues and delivery/DNS waits take additional time. This lab covers restricted image storage and ownership. Client checks and MIME settings do not constitute a complete malware/content-validation pipeline for arbitrary public uploads.
What you will learn
- Distinguish a local preview from a stored upload.
- Test allowed and rejected supplied files.
- Check owner-only deletion and another account’s limits.
Step 1
Understand what the preview proves
A selected filename, a stored upload and a readable image are three different observations.
Open the supplied app with your assistant and choose fixtures/avatar-small.webp. Before pressing Upload image, the file control shows your selected filename. This starter does not create a local image preview at selection time; its image appears only after upload and signed access succeed.
Other apps can preview a local image without storing it. In this app too, selecting a filename alone proves no remote upload. Keep selection, provider storage and the later image read as separate checks.
A concrete example
Selecting avatar-small.webp can show the filename before the storage account is configured. To establish remote storage later, find the uploaded object in the provider and check the signed preview that reads it.
Use the complete image-upload workshop and my disposable Supabase project. Help configure sign-in, a private avatars bucket, the stated 2 MB limit and allowed image formats with the provided policies. Keep private keys out of public files. Run the page and guide me through small/oversized/unsupported-file tests and separate-account deletion checks. Handle code changes for me.Files for this step

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
How it works (optional)
Store the image, not just a local preview
A preview created from a selected file is not evidence that a storage service received it.
The browser first holds the selected file. Uploading sends its bytes to an object-storage service, which gives it a path and applies access rules.
We will use a private Supabase bucket with one owner folder per account. The app uploads a file, then asks for a short-lived signed preview URL. It does not make every upload publicly readable.
Worked example
A local blob: preview can work without any network request. Our test will inspect the actual object and retrieve it through an authorized route.
Extra implementation exercise
The selected image appears instantly through a blob URL. Has the upload necessarily happened?
Show a worked solution
No. Verify the storage operation and matching object before claiming an upload.
- Separates local preview from remote storage.
- Checks the upload result and stored object.
Common mistake
Calling file selection a completed upload.
Step 2
Prepare private test storage
Use the supplied settings and an assistant for the setup.
In your disposable project, have the assistant configure the private avatars bucket, size/format limits and policies.sql. Launch the complete sign-in/upload app over HTTP.
Confirm the bucket is private and the account/project is the intended one. Do not remove storage protections to make a failed request succeed.
A concrete example
The visitor interface can help reject a file, but the storage service must enforce its own rules too.
Supabase: storage access control
Try it yourself
Which storage settings were applied, and can your test account open the running app?
Discuss your answer with the lesson tutor
Show a worked solution
Illustrative setup record: “The assistant prepared the private avatars bucket in the disposable project, set the stated 2 MB PNG/JPEG/WebP limits and applied the supplied owner-folder policies. The HTTP app opens and A can sign in.”
If upload fails before those checks are complete, record which setup stage is missing. Making the bucket public or removing ownership rules is not a valid shortcut.
- Identifies the disposable project, private avatars bucket and configured format/size limits.
- Records the running sign-in/upload app and any setup blocker without weakening storage protections.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
How it works (optional)
Create a private bucket and owner rules
Bucket configuration and access policies enforce different parts of the task.
Create the avatars bucket as private. Configure its 2MB size limit and allowed MIME types, then apply policies.sql. Browser roles should only insert and read paths under their verified user ID.
The client’s accept attribute is a convenience, not a security check. Provider size/type rules and ownership policies still apply to direct requests. MIME labels alone do not prove arbitrary file content is safe; do not present this lab as a complete scanning service.
For an object named USER_A/avatar-1.webp, storage.foldername(name) returns the folder components; [1] selects the first one in this PostgreSQL array. It must equal the authenticated user's ID. USER_B/avatar-1.webp fails for account A. This storage-side rule is distinct from the browser's file picker and MIME precheck.
The first path segment remains the user ID even with nested folders: USER_A/subfolder/avatar.webp still has USER_A as folder component [1]. A path beginning subfolder/USER_A/... would not match. Keep the owner ID first; do not loosen the policy just to accommodate a mistaken path.
Worked example
The folder prefix comes from the signed-in user, while the database policy compares it with auth.uid(). Changing a browser path to another user’s folder should not grant permission.
create policy "upload own avatar" on storage.objects for insert to authenticated
with check (bucket_id='avatars' and (storage.foldername(name))[1]=auth.uid()::text);
create policy "read own avatar" on storage.objects for select to authenticated
using (bucket_id='avatars' and (storage.foldername(name))[1]=auth.uid()::text);
Supabase: storage access control
Extra implementation exercise
Why is checking the filename extension only in JavaScript insufficient?
Show a worked solution
A caller can send a direct request with different metadata or a different path. Enforce the intended bucket and owner rules at the service boundary.
- Recognizes the caller can bypass JavaScript.
- Requires storage-side restrictions and authorization.
Common mistake
Making the entire bucket public to repair a failed preview.
Step 3
Upload the small test image
Check the stored object as well as the visible picture.
Sign in as account A and upload the supplied small image. Find its object in the provider and use the resulting preview or signed access route.
If storage succeeds but preview fails, investigate reading/preview before uploading another copy. Keep the recorded object reference.
A concrete example
A missing preview does not necessarily mean the upload itself failed.
Try it yourself
Was the small image stored, and could it be read afterward?
Discuss your answer with the lesson tutor
Show a worked solution
Illustrative upload record: “A uploaded avatar-small.webp. The provider showed an object under A’s folder; I saved its redacted reference. The image then appeared through the short-lived signed preview.”
A partial result could read: “The object exists, but preview access failed.” That calls for a read/access check on the same object, rather than uploading repeated copies without knowing whether storage succeeded.
- Links A’s successful upload to the actual stored object reference.
- Separately records whether the signed preview could read that object.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
How it works (optional)
Upload to a unique owner path
Use a generated name instead of trusting a caller’s path or overwriting an existing file.
After sign-in, the app chooses a path using the verified user ID and a random filename. It checks the selected image’s size/type before requesting an upload, but those checks do not replace provider enforcement.
The upload does not enable upsert. If storage succeeds but signed-URL creation fails, the UI reports those as separate observations. It never says “nothing uploaded” when the object may already exist.
Worked example
A generated filename avoids accidental collisions with another picture named photo.jpg. It is not an authorization mechanism by itself.
Extra implementation exercise
The object exists, but preview creation failed. Should you immediately upload another copy?
Show a worked solution
Check the object path and read policy first. Re-uploading can create duplicates without repairing the preview problem.
- Keeps upload success separate from preview authorization.
- Investigates read policy/path before creating duplicates.
Common mistake
Treating random filenames as a substitute for access control.
Step 4
Try the supplied failure cases
The exercise includes files that should not upload.
Use fixtures/avatar-too-large.png and fixtures/not-an-image.txt. Record how the page and storage respond. Ask the assistant to inspect a rejection that is confusing or an invalid file that slipped through.
Rejected files must not become stored objects. A valid signed URL can allow its holder to view an image for its lifetime; that alone is not proof that the bucket became public.
A concrete example
A file-picker restriction and real storage enforcement are different checks.
Try it yourself
What happened for the oversized and unsupported files, and what access route did you actually test?
Discuss your answer with the lesson tutor
Show a worked solution
Illustrative rejection record: “The oversized PNG was rejected and no new object appeared. The text file was rejected too; the assistant helped test it if the file picker hid unsupported formats.”
“The allowed image’s signed URL opened during its short lifetime. That showed access through that URL, not that the private bucket became public.” A file-picker filter alone is not a direct test of the provider’s storage limits.
- Records separate rejection and storage observations for both supplied invalid files.
- Distinguishes a temporary signed-link read from unrestricted public-bucket access.
Files for this step

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
How it works (optional)
Verify rejection and temporary access
Test the service rules and understand what a signed link grants.
Upload fixtures/avatar-small.webp as account A. Inspect its storage path and open the authorized signed preview. Then try fixtures/avatar-too-large.png (over 2MiB) and fixtures/not-an-image.txt (unsupported type); both should be rejected. All three files are supplied with the lesson.
Use account B to request a signed link for A’s path; the owner policy should deny it. A signed URL legitimately issued to A can still be used by anyone who obtains it until expiry. Client sign-out does not instantly revoke every issued URL.
Worked example
A useful report records a redacted path and expiry duration, not the full temporary access URL.
Extra implementation exercise
Someone with a valid signed URL opens the image without signing in. Does that alone prove the private bucket policy failed?
Show a worked solution
No. Test whether an unauthorized account can create the URL or read without an authorized capability. Treat issued URLs as sensitive until they expire.
- Recognizes signed URLs as temporary bearer capabilities.
- Distinguishes URL access from permission to create one.
Common mistake
Publishing a signed URL in a bug report and expecting it to remain private.
Step 5
Add owner-only deletion
Verify who can remove the uploaded object.
Ask the assistant to add the supplied owner-deletion behavior. As A, delete a first test object X and verify it is absent in storage. Then upload a new object Y as A; keep Y’s redacted reference for the next check.
In B’s separate session, have the assistant target Y for a direct deletion attempt. Record actor B, target Y and the provider result, then verify that A’s Y still exists. Checking only a hidden delete button, or trying to delete already-missing X again, would not establish this ownership boundary.
A concrete example
Removing an image from the screen is not the same as deleting the stored object.
Try it yourself
Start with these materials
The starter files and test content are supplied. A live verification still requires your own permitted provider account, inbox or domain as listed under prerequisites. Local inspection is possible without them; record the live step as not tested until you actually perform it.
Provide owner deletion and the second-account attempt with actual object results.
What to produce The upload/delete result and actual valid, oversized, unsupported and cross-account checks.
Discuss your answer with the lesson tutor
Show a worked solution
Illustrative deletion record: “A deleted object X and the provider confirmed X was absent. A then uploaded fresh object Y. B’s separate session attempted to delete Y; A checked that Y still existed.”
The assistant should identify actor B and target Y before running the isolated test. Attempting to delete X again would test an already-missing object, not owner-only protection.
- Deletes A’s first object as its owner and verifies that exact object is gone.
- Uploads a fresh A-owned object, targets it from B and verifies that it remains stored.
Files for this step

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
- policies.sqlDownload this file
- public/app.jsDownload this file
- upload-tests.txtDownload this file
- worksheet.htmlDownload this file
- reference/assignment-walkthrough.txtDownload this file
- reference/START-HERE.txtDownload this file
- reference/public/index.htmlDownload this file
- reference/public/app.jsDownload this file
- reference/delete-policy.sqlDownload this file
- fixtures/avatar-small.webpDownload this file
- fixtures/avatar-too-large.pngDownload this file
- fixtures/not-an-image.txtDownload this file
How it works (optional)
Your assignment: add owner-only deletion
A new operation needs its own policy and negative tests.
Add a delete control for the uploaded object and a DELETE policy restricted to its owner folder. Do not broaden the existing bucket into a public shared area.
Verify that A can remove A’s object and B cannot remove it. Keep the storage state consistent with the UI after a failed deletion.
Worked example
The original policies intentionally allow insert/read only. Deletion is not automatically authorized by an upload permission.
The complete reference walkthrough is available in reference/assignment-walkthrough.txt. Compare its steps with your own result; fill the test record from observations in your own project.
Extra implementation exercise
Implement owner-only deletion and demonstrate both allowed and forbidden attempts.
Show a worked solution
Use a private avatars bucket with storage-side size/type settings and owner-folder policies. Upload an allowed image as account A; inspect the returned storage result, then open the short-lived signed preview. A blob preview alone proves no remote upload.
Try an unsupported or oversized file and attempt an upload/read under account B's folder. A must not gain access merely by changing a path in developer tools. Signed URLs intentionally grant temporary access until their expiry.
For deletion, add a DELETE policy using the same bucket/owner-folder condition and call remove with the exact stored path. Verify the object is absent afterward and a cross-owner deletion leaves the other owner's object intact. The reference deletion module is separate so you can inspect the path and policy before integrating it.
- Delete permission checks the bucket and verified owner folder.
- Failed attempts do not remove another account’s object or falsely clear the UI.
Common mistake
Granting DELETE to every authenticated user just to make a button work.
Was this lesson useful?
Leave a like, or share it with someone who could use it.
Continue learning
- How to build your first personal website
- How to publish your website from GitHub
- How to connect a custom domain to your website
- How to set up email on your own domain
- How to make your website usable on phones
- How to make website images load faster
- How to get website feedback in your inbox
- How to add email subscriptions to your website
- How to send automated emails from your website
- How to save form submissions in a database
- How to let people sign in to your website
- How to keep a page private
- How to let users edit their profile information
- How to keep API keys out of your frontend
- How to show data from an external API on your website
- How to add an AI chatbot to your website
- How to make a chatbot answer from your own content
- How to add a blog to your website
- How to add search to your website
- How to add another language to your website
- How to help Google find your website
- How to fix your website preview when sharing a link
- How to measure visits and useful actions on your website
- How to let visitors book an appointment
- How to accept a payment on your website
- How to preview website changes before publishing
- How to undo a broken website deployment
- How to back up and restore your website data
- How to find and fix errors on your live website