
How to upload files to amazon s3 bucket using Laravel
How to upload files to amazon s3 bucket using Laravel
Hello everyone, in this post we will look at how to solve "How to upload files to amazon s3 bucket using Laravel" in programming.
You can upload files to amazon s3 bucket using Laravel. You just have to provide access key id, secret access key, default region and aws_bucket in .env file and use code Storage::disk('s3')->put('file-path/filename.jpg', file_get_contents($request->file)) to upload the file in the specified directory.-
Upload file to amazon s3 bucket using Laravel
$file = $request->document; $fileName = Str::uuid().'.'.$request->document->extension(); $filePath = 'project/documents/'; $path = Storage::disk('s3')->put($filePath.$fileName, file_get_contents($file)); $s3URL = Storage::disk('s3')->url($path);
Additional info
Provide AWS credentials in .env file
AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX AWS_DEFAULT_REGION=XX-XXXXXXXXX-X AWS_BUCKET=XXXXXXXXXXXX
Use (import) storage facade and Str
use Illuminate\Support\Str; use Illuminate\Support\Facades\Storage;
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Get Array of IDs from Eloquent Collection
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- Ajax GET request in laravel
- Illuminate\Database\QueryException could not find driver
- Insert data with form validation using ajax in laravel
- Generate unique username in Laravel
- Laravel form request validation
- Insert current date time in a column using Laravel
- How to pass query string to url in laravel
- Create record with unique slug in laravel
- Redirect to another view from controller in laravel
- How to restore multiple records after soft-deletes in Laravel
- Update email with unique validation in laravel
- How to send email in laravel
- How to start websocket server in laravel
- Class 'App\Http\Controllers\User' not found
- Class 'App\Rules\Hash' not found in Laravel
- How to display pivot table column value in laravel
- Permission denied error while creating storage link in Laravel
- Rename Pivot Table in Laravel
- Print query in laravel
- Display data in table using foreach in Laravel
- Check if Relationship Method Exists in Laravel
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- How to disable timestamps in laravel