A public URL is a web link that anyone can use to access a file stored in Supabase Storage without needing special permissions or login.
Click to reveal answer
beginner
How do you make a file publicly accessible in Supabase Storage?
You set the file or bucket to public, then generate a public URL that points directly to the file, allowing anyone to view or download it.
Click to reveal answer
intermediate
Which Supabase Storage method generates a public URL for a file?
The method is `getPublicUrl(path)`, where `path` is the location of the file in the storage bucket.
Click to reveal answer
intermediate
Why should you be careful when generating public URLs for files?
Because public URLs allow anyone to access the file, sensitive or private data should never be shared this way to avoid security risks.
Click to reveal answer
intermediate
What is the difference between a public URL and a signed URL in Supabase?
A public URL is open to everyone, while a signed URL is temporary and includes a token that grants access only for a limited time.
Click to reveal answer
Which method in Supabase Storage generates a public URL for a file?
AcreateSignedUrl(path)
BuploadFile(path)
CgetPublicUrl(path)
DdeleteFile(path)
✗ Incorrect
The method getPublicUrl(path) returns a public URL for the file at the given path.
What must be true for a file to be accessible via a public URL in Supabase?
AThe file must be encrypted
BThe file or bucket must be set to public
CThe user must be logged in
DThe file must be signed
✗ Incorrect
Only files or buckets set to public can be accessed via public URLs without authentication.
What is a risk of sharing public URLs for files?
AThe file becomes read-only
BThe file will be deleted automatically
CThe file size increases
DAnyone can access the file, risking data exposure
✗ Incorrect
Public URLs allow anyone to access the file, so sensitive data can be exposed.
How does a signed URL differ from a public URL in Supabase?
ASigned URLs expire after a set time, public URLs do not
BSigned URLs are always public
CPublic URLs require login
DSigned URLs cannot be used to download files
✗ Incorrect
Signed URLs include a token and expire after a time, limiting access duration.
Which of these is NOT a valid reason to use a public URL?
ASharing private user data
BAllowing anyone to download a public document
CLinking to a public video file
DSharing a public image on a website
✗ Incorrect
Private user data should never be shared via public URLs to protect privacy.
Explain how to generate a public URL for a file in Supabase Storage and what settings are required.
Think about permissions and the API method used.
You got /3 concepts.
Describe the security considerations when using public URLs in Supabase.
Consider who can see the file and for how long.
You got /3 concepts.
Practice
(1/5)
1. What does the getPublicUrl function in Supabase do?
easy
A. It creates a link that anyone can use to access a file in a bucket.
B. It deletes a file from the storage bucket.
C. It uploads a file to the storage bucket.
D. It encrypts a file before storing it.
Solution
Step 1: Understand the purpose of getPublicUrl
This function is designed to generate a URL that can be shared publicly to access a file stored in Supabase storage.
Step 2: Compare options with function behavior
Only It creates a link that anyone can use to access a file in a bucket. describes creating a public link. Other options describe unrelated actions like deleting, uploading, or encrypting files.
Final Answer:
It creates a link that anyone can use to access a file in a bucket. -> Option A
Quick Check:
Public URL = Link to file [OK]
Hint: Public URLs let anyone access files without login [OK]
Common Mistakes:
Confusing URL generation with file upload
Thinking it deletes files
Assuming it encrypts files automatically
2. Which of the following is the correct way to call getPublicUrl in Supabase to get a public URL for a file named photo.jpg in bucket images?
easy
A. supabase.getPublicUrl('images', 'photo.jpg')
B. supabase.storage.getPublicUrl('images/photo.jpg')
C. supabase.storage.from('images').getPublicUrl('photo.jpg')
D. supabase.storage.from('photo.jpg').getPublicUrl('images')
Solution
Step 1: Recall the correct method chaining
The correct syntax is to select the bucket first with from('bucket_name'), then call getPublicUrl('file_path').
Step 2: Match options with correct syntax
supabase.storage.from('images').getPublicUrl('photo.jpg') matches this pattern exactly. Options A, B, and D misuse method calls or argument order.
Final Answer:
supabase.storage.from('images').getPublicUrl('photo.jpg') -> Option C
Quick Check:
Bucket then file path = Correct call [OK]
Hint: Use .from(bucket).getPublicUrl(file) syntax [OK]
Common Mistakes:
Calling getPublicUrl directly on storage
Swapping bucket and file arguments
Using wrong method names
3. What will be the output of this code snippet?
const { data } = supabase.storage.from('docs').getPublicUrl('file.txt'); console.log(data.publicUrl);
medium
A. A boolean indicating if the file exists.
B. A string URL to access 'file.txt' publicly in 'docs' bucket.
C. Undefined because 'data' is not returned by getPublicUrl.
D. An error because getPublicUrl returns a promise.
Solution
Step 1: Understand getPublicUrl return value
The getPublicUrl method returns an object with a publicUrl string property immediately, not a promise.
Step 2: Analyze the console.log output
Logging data.publicUrl will print the URL string to access the file publicly.
Final Answer:
A string URL to access 'file.txt' publicly in 'docs' bucket. -> Option B
Quick Check:
getPublicUrl returns URL string [OK]
Hint: getPublicUrl returns URL object, not a promise [OK]
Common Mistakes:
Assuming getPublicUrl is async
Expecting undefined data
Confusing output with file existence check
4. You tried to generate a public URL with supabase.storage.from('media').getPublicUrl('video.mp4') but got an empty string. What is the most likely cause?
medium
A. getPublicUrl requires an async await call.
B. You forgot to import the Supabase client.
C. The bucket name should be 'videos' not 'media'.
D. The file 'video.mp4' does not exist in the 'media' bucket.
Solution
Step 1: Check file existence in bucket
If the file does not exist, the public URL generated will be empty or invalid.
Step 2: Evaluate other options
Importing client or bucket name mismatch would cause errors, not empty string. getPublicUrl is synchronous, so async is not needed.
Final Answer:
The file 'video.mp4' does not exist in the 'media' bucket. -> Option D
Quick Check:
Missing file = empty URL [OK]
Hint: Empty URL usually means file missing [OK]
Common Mistakes:
Assuming getPublicUrl is async
Ignoring file existence
Mixing up bucket names
5. You want to share a file publicly but keep other files private in the same bucket. Which approach with Supabase storage and getPublicUrl is best?
hard
A. Use getPublicUrl only on files in a public bucket.
B. Set the bucket to private, then generate public URLs only for specific files using getPublicUrl.
C. Make the entire bucket public so all files are accessible.
D. Upload files with a special tag to mark them public.
Solution
Step 1: Understand bucket privacy settings
Supabase storage buckets are either public or private. Public buckets allow all files to be accessed via public URLs.
Step 2: Evaluate file-level public access
Supabase does not support per-file public access in private buckets. To share files publicly, the bucket must be public.
Step 3: Choose best practice
Use getPublicUrl only on files in a public bucket. correctly states to use getPublicUrl on files in a public bucket to share them. Options A and D are incorrect because file-level public control is not supported. Make the entire bucket public so all files are accessible. makes all files public, which is not desired.
Final Answer:
Use getPublicUrl only on files in a public bucket. -> Option A
Quick Check:
Public URLs need public bucket [OK]
Hint: Only public buckets support public URLs per file [OK]
Common Mistakes:
Thinking private buckets allow public URLs per file
Making whole bucket public without control
Assuming tags control public access
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.