📖 Scenario: You are setting up a cloud project to store files securely. You will create storage buckets to organize and manage your files in Supabase.
🎯 Goal: Build a Supabase storage setup by creating a dictionary of buckets, add a configuration for public access, then write the code to create these buckets using Supabase's API.
📋 What You'll Learn
Create a dictionary called buckets with exact bucket names and descriptions
Add a configuration variable called public_access set to False
Write a loop using for bucket_name, bucket_info in buckets.items() to create buckets
Use supabase.storage.create_bucket with bucket_name and public=public_access to create each bucket
💡 Why This Matters
🌍 Real World
Cloud projects often need organized storage for files. Creating buckets helps separate and secure different file types.
💼 Career
Knowing how to programmatically create and configure storage buckets is essential for cloud engineers and developers managing cloud storage.
Progress0 / 4 steps
1
Create the initial buckets dictionary
Create a dictionary called buckets with these exact entries: 'images': 'Stores user images', 'documents': 'Stores user documents', and 'backups': 'Stores backup files'.
Supabase
Hint
Use curly braces to create a dictionary with keys and values as shown.
2
Add public access configuration
Add a variable called public_access and set it to False to configure bucket privacy.
Supabase
Hint
Use a simple assignment statement to set public_access.
3
Write the loop to create buckets
Write a for loop using for bucket_name, bucket_info in buckets.items() to iterate over the buckets dictionary.
Supabase
Hint
Use the items() method to get keys and values from the dictionary.
4
Complete bucket creation with Supabase API
Inside the loop, call supabase.storage.create_bucket(bucket_name, public=public_access) to create each bucket with the configured public access.
Supabase
Hint
Use the create_bucket method with the bucket name and public parameter.
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
Step 1: Understand storage bucket purpose
A storage bucket is used to hold and organize files securely in the cloud.
Step 2: Compare options
Options B, C, and D describe other services not related to file storage.
Final Answer:
To organize and protect files in the cloud -> Option D
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
Step 1: Recall correct method signature
The method createBucket takes the bucket name and an options object with a public boolean.
Step 2: Identify correct privacy option
Setting public: false makes the bucket private. Other options use incorrect keys.
Final Answer:
supabase.storage.createBucket('photos', { public: false }) -> Option B
Quick Check:
Use public: false for private bucket [OK]
Hint: Use public: false to make bucket private [OK]