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
- InRandomOrder() method with example in laravel
- How to add columns in existing table using migration in laravel
- Laravel delete all rows older than 30 days
- In order to use the Auth::routes() method, please install the laravel/ui package
- The use statement with non-compound name 'Auth' has no effect
- How to get selected categories on edit record with Select2
- How to get specific columns using Laravel eloquent methods
- Save or update pivot table data with additional column in Laravel
- How to Get records between two dates in Laravel
- Validation for multiple forms on same page in laravel
- Ignore Records where a field has NULL value in Laravel
- Trying to get property 'title' of non-object
- Get last record from table in laravel
- Display success message in laravel
- On delete set foreign id column value null using migration in laravel 8
- How to create belongstomany relation using custom name on custom pivot table
- How to insert value to additional columns in pivot table in laravel
- Insert dummy data in users table Laravel
- How to Access Array in blade laravel
- How to get last year records count with month wise in Laravel
- How to check if user has created any post or not in laravel
- Cannot end a section without first starting one
- How to update record after save method in Laravel
- Illuminate\Database\QueryException could not find driver
- Laravel migration add foreign key to existing table