
How to upload files to amazon s3 bucket using Laravel
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.
Answers 1
-
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);
0Additional 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;
Random Code Snippet Queries: Laravel
- How to get CSRF token in laravel controller
- External link not working in laravel blade
- Return view from route Laravel
- Get products with number of orders in Laravel
- How to get last month records in Laravel
- Method Illuminate\Database\Eloquent\Collection::appends does not exist
- How to pass variable from controller to model in Laravel
- How to check relationship is loaded or not in Laravel
- How to use bootstrap pagination in laravel 8
- How to create and run user seeder in laravel
- How to check if user has created any post or not in laravel
- SQLSTATE[42000]: Syntax error or access violation: 1055
- How to validate website url in laravel using validaiton
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- How to send email in laravel
- There are no commands defined in the "route:" namespace
- Calculate age from date of birth in Laravel
- Recursive function example code PHP Laravel
- How to add foreign key in laravel using migration
- Import/Use Storage facade in laravel
- Insert values in pivot table dynamically in laravel
- Wheredate in laravel not working
- Call to undefined method Illuminate\Support\Facades\Request::all()
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- Get laravel version