Bird
Raised Fist0
Supabasecloud~10 mins

Creating storage buckets in Supabase - Visual Walkthrough

Choose your learning style10 modes available
Process Flow - Creating storage buckets
Start
↓
Initialize Supabase Client
↓
Call createBucket API
↓
Check API Response
↓
Bucket Created
↓
End
This flow shows how to create a storage bucket by initializing the client, calling the create bucket API, and handling success or error responses.
Execution Sample
Supabase
const { data, error } = await supabase.storage.createBucket('photos', { public: true });
This code creates a public storage bucket named 'photos' using Supabase storage API.
Process Table
StepActionAPI CallResponseResult
1Initialize Supabase clientN/AClient readyReady to create bucket
2Call createBucket with name 'photos' and public truecreateBucket('photos', {public:true})Success: bucket createdBucket 'photos' created
3Verify bucket creationN/ABucket existsReady for use
4End processN/AN/AProcess complete
💡 Bucket 'photos' created successfully, process ends.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
supabaseClientundefinedinitializedinitializedinitializedinitialized
dataundefinedundefined{ id: 'photos', public: true }{ id: 'photos', public: true }{ id: 'photos', public: true }
errorundefinedundefinednullnullnull
Key Moments - 2 Insights
Why do we check the 'error' variable after calling createBucket?
Because the API might fail to create the bucket (e.g., name taken), checking 'error' (see execution_table step 2) tells us if creation succeeded or failed.
What does setting 'public: true' do when creating the bucket?
It makes the bucket accessible publicly, meaning files inside can be accessed without authentication. This is shown in the API call options in execution_table step 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table at step 2, what is the value of 'error' after calling createBucket?
Anull
BAn error message
Cundefined
Dtrue
💡 Hint
Check the 'Response' and 'Result' columns at step 2 in the execution_table.
At which step does the bucket become ready for use?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at the 'Result' column describing bucket status in execution_table.
If the bucket name was already taken, how would the execution_table change at step 2?
ANo change, bucket created anyway
BResponse would show success and error would be null
CResponse would show an error and error variable would contain details
DProcess would skip step 2
💡 Hint
Refer to key_moments about error checking after createBucket call.
Concept Snapshot
Creating storage buckets in Supabase:
- Initialize Supabase client
- Call createBucket('bucket-name', { public: true/false })
- Check 'error' to confirm success
- Bucket is ready if no error
- Public option controls access
Full Transcript
To create a storage bucket in Supabase, first initialize the Supabase client. Then call the createBucket API with the desired bucket name and options like public access. After the call, check the error variable to see if the bucket was created successfully. If there is no error, the bucket is ready to use. Setting public to true makes the bucket accessible without login. This process ensures your storage bucket is created and ready for storing files.

Practice

(1/5)
1. What is the main purpose of creating a storage bucket in Supabase?
easy
A. To send emails automatically
B. To run server-side code
C. To create a database table
D. To organize and protect files in the cloud

Solution

  1. Step 1: Understand storage bucket purpose

    A storage bucket is used to hold and organize files securely in the cloud.
  2. Step 2: Compare options

    Options B, C, and D describe other services not related to file storage.
  3. Final Answer:

    To organize and protect files in the cloud -> Option D
  4. Quick Check:

    Storage bucket = organize and protect files [OK]
Hint: Buckets store files safely in the cloud [OK]
Common Mistakes:
  • Confusing buckets with databases
  • Thinking buckets run code
  • Assuming buckets send emails
2. Which is the correct way to create a private storage bucket named photos in Supabase?
easy
A. supabase.storage.createBucket('photos', { access: 'private' })
B. supabase.storage.createBucket('photos', { public: false })
C. supabase.storage.createBucket('photos', { private: true })
D. supabase.storage.createBucket('photos', { isPublic: true })

Solution

  1. Step 1: Recall correct method signature

    The method createBucket takes the bucket name and an options object with a public boolean.
  2. Step 2: Identify correct privacy option

    Setting public: false makes the bucket private. Other options use incorrect keys.
  3. Final Answer:

    supabase.storage.createBucket('photos', { public: false }) -> Option B
  4. Quick Check:

    Use public: false for private bucket [OK]
Hint: Use public: false to make bucket private [OK]
Common Mistakes:
  • Using wrong option keys like isPublic or private
  • Setting public: true for private buckets
  • Confusing access property with public
3. What will be the result of this code snippet?
const { data, error } = await supabase.storage.createBucket('docs', { public: true });
console.log(data);
medium
A. An error because 'public' is not a valid option
B. Undefined because createBucket returns nothing
C. An object with bucket details including name 'docs' and public true
D. A boolean true indicating success

Solution

  1. Step 1: Understand createBucket return value

    The method returns an object with bucket info if successful, including name and public status.
  2. Step 2: Analyze the code output

    Since public: true is valid, data will contain bucket details, not an error or boolean.
  3. Final Answer:

    An object with bucket details including name 'docs' and public true -> Option C
  4. Quick Check:

    createBucket returns bucket info object [OK]
Hint: createBucket returns bucket info object on success [OK]
Common Mistakes:
  • Thinking it returns only true/false
  • Assuming it throws error for public option
  • Expecting no return value
4. You wrote this code but get an error:
await supabase.storage.createBucket('files', { public: 'no' });

What is the likely cause?
medium
A. The 'public' option must be a boolean, not a string
B. Bucket name 'files' is invalid
C. createBucket requires a callback function
D. Missing await keyword before createBucket

Solution

  1. Step 1: Check option types

    The public option expects a boolean true or false, not a string.
  2. Step 2: Identify error cause

    Passing 'no' as a string causes a type error. Bucket name and await usage are correct.
  3. Final Answer:

    The 'public' option must be a boolean, not a string -> Option A
  4. Quick Check:

    public option = boolean, not string [OK]
Hint: Use true/false for public, not strings [OK]
Common Mistakes:
  • Passing 'yes' or 'no' as strings
  • Ignoring await keyword
  • Using invalid bucket names
5. You want to create two buckets: one public named images and one private named backups. Which code correctly does this?
hard
A. await supabase.storage.createBucket('images', { public: true }); await supabase.storage.createBucket('backups', { public: false });
B. await supabase.storage.createBucket('images', { public: false }); await supabase.storage.createBucket('backups', { public: true });
C. await supabase.storage.createBucket('images'); await supabase.storage.createBucket('backups');
D. await supabase.storage.createBucket('images', { access: 'public' }); await supabase.storage.createBucket('backups', { access: 'private' });

Solution

  1. Step 1: Set correct privacy flags

    Public bucket needs public: true, private bucket needs public: false.
  2. Step 2: Verify method calls

    await supabase.storage.createBucket('images', { public: true }); await supabase.storage.createBucket('backups', { public: false }); correctly sets these flags. await supabase.storage.createBucket('images', { public: false }); await supabase.storage.createBucket('backups', { public: true }); reverses them. await supabase.storage.createBucket('images'); await supabase.storage.createBucket('backups'); omits privacy, defaulting to private. await supabase.storage.createBucket('images', { access: 'public' }); await supabase.storage.createBucket('backups', { access: 'private' }); uses invalid keys.
  3. Final Answer:

    await supabase.storage.createBucket('images', { public: true }); await supabase.storage.createBucket('backups', { public: false }); -> Option A
  4. Quick Check:

    Public = true, Private = false [OK]
Hint: Public bucket: public true; Private bucket: public false [OK]
Common Mistakes:
  • Mixing up public true/false
  • Omitting privacy option
  • Using wrong option keys like access
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard