You will create a public avatars bucket where signed-in people can upload to their own folder.

1. Create the bucket in Studio

  1. Open your project and choose the development environment.
  2. In the sidebar choose Storage (under Services).
  3. Click New bucket.
  4. Set Name to avatars.
  5. Turn on Public bucket (anyone with an object’s URL may read it; uploads, listing and deletes still follow the rules below).
  6. Under Who may upload new objects, open the rule picker and choose Custom condition. Add one rule: Compare values… with $object.segments.0 equals $auth.user_id. This means a person can upload only under their own id.
  7. Under Uploads, set Accepted types to image/* and Largest file to 2 (MB).
  8. Click Create.
The bucket appears in the list. Click it to open the file browser.

2. Upload a file in Studio

In the file browser click Upload, choose an image. It appears in the list with its size and type. Click it to open its panel: the Overview tab shows its Gateway URL, the address your app uses.

3. Upload from your app

Sign a person in first (Auth), then:

4. Prove the rule

Try to upload to someone else’s folder:
Check it in Studio: open Activity and find the refused request. See Debugging rules.

What you have now

  • A public bucket that only accepts images up to 2 MB.
  • A rule that keeps people to their own folder.
  • A URL you can put in an <img>.

Bucket settings

Every setting explained.

Upload

Large files, progress, errors.