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
- How to Access Array in blade laravel
- Get laravel version
- Redirect to another view from controller in laravel
- How to get route name on visit URL in laravel
- How to create new user without form submission in laravel
- Illuminate\Database\QueryException could not find driver
- How to insert dynamic value to additional column in pivot table in laravel
- Get current URL on visit URL in Laravel
- Extra Filter Query on Relationships in Laravel
- How to return a column with different name in Laravel
- Permission denied error while creating storage link in Laravel
- Best code example for create order in Laravel for ecommerce
- How to avoid duplicate entries in pivot table in Laravel
- There are no commands defined in the "route:" namespace
- Send OTP using textlocal api in laravel
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- Post model with title and body in laravel 8
- How to check duplicate entry in laravel
- Laravel 9 pagination with search filter
- How to get only time from created_at in laravel
- Call to undefined method App\Models\User::follow()
- Class 'App\Providers\Auth' not found
- Get count of filter data, while return a small set of records
- If condition in foreach loop in laravel
- How to display order by null last in laravel