Challenge - 5 Problems
S3 Storage Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Laravel code snippet using S3 storage?
Consider this Laravel controller method that uploads a file to S3 and returns the file URL.
What will be the output when this method is called successfully?
What will be the output when this method is called successfully?
Laravel
<?php
use Illuminate\Support\Facades\Storage;
public function uploadFile(Request $request) {
$path = Storage::disk('s3')->put('uploads', $request->file('photo'));
return Storage::disk('s3')->url($path);
}Attempts:
2 left
💡 Hint
Think about what Storage::disk('s3')->url() returns.
✗ Incorrect
Storage::disk('s3')->put() uploads the file and returns the path. Then Storage::disk('s3')->url() returns the full public URL to access the file on S3.
📝 Syntax
intermediate2:00remaining
Which option correctly configures the S3 disk in Laravel's filesystems.php?
You want to add an S3 disk configuration in config/filesystems.php. Which option is syntactically correct?
Attempts:
2 left
💡 Hint
Check the exact keys Laravel expects for S3 config.
✗ Incorrect
Laravel expects 'key', 'secret', 'region', and 'bucket' keys with env() calls for credentials. Option A matches the correct keys and env variable names.
🔧 Debug
advanced2:00remaining
Why does this Laravel S3 upload code throw an error?
This code snippet throws an error when uploading a file to S3. What is the cause?
Laravel
<?php
use Illuminate\Support\Facades\Storage;
public function upload(Request $request) {
$file = $request->file('image');
$path = Storage::disk('s3')->putFile('images', $file);
return $path;
}
// Error: Argument 1 passed to putFile() must be a string, null givenAttempts:
2 left
💡 Hint
Check what $request->file('image') returns if no file is uploaded.
✗ Incorrect
If the request does not have a file named 'image', $request->file('image') returns null. Passing null to putFile() causes the error.
❓ state_output
advanced2:00remaining
What is the value of $exists after this Laravel S3 code runs?
Given this code snippet, what will be the value of $exists?
Laravel
<?php use Illuminate\Support\Facades\Storage; $filename = 'documents/report.pdf'; $exists = Storage::disk('s3')->exists($filename);
Attempts:
2 left
💡 Hint
What does Storage::disk('s3')->exists() check?
✗ Incorrect
The exists() method returns true if the file exists in the S3 bucket, false if it does not.
🧠 Conceptual
expert3:00remaining
Which option best explains why Laravel uses Flysystem for S3 integration?
Laravel uses the Flysystem PHP package to integrate with S3. Why is this approach beneficial?
Attempts:
2 left
💡 Hint
Think about abstraction and flexibility in storage APIs.
✗ Incorrect
Flysystem abstracts different storage backends behind one API. This lets Laravel switch storage drivers easily without changing code.