
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 add dynamic page title in Laravel view
- On delete set foreign id column value null using migration in laravel 8
- Laravel create table migration with model
- How to disable timestamps in laravel
- JQuery each loop on json response after ajax in laravel
- Delete file from amazon s3 bucket using Laravel
- Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
- Laravel hasmany select not working
- How to check records exist in loaded relationship in Laravel blade view
- How to display HTML tags In Laravel blade
- Redirect from www to non www in laravel using htaccess
- Symlink(): No such file or directory
- How to insert dynamic values to additional column with pivot column in pivot table on multiple records
- How to get records in random order in laravel
- Conditional where clause in Laravel
- How to get last record from object collection in laravel
- In order to use the Auth::routes() method, please install the laravel/ui package
- Get current month records in laravel 7/8
- Get content from web URL in laravel
- Attempt to read property "avatar" on null in Laravel
- How to pass query string to url in laravel
- Class 'Facade\Ignition\IgnitionServiceProvider' not found
- Get current URL on visit URL in Laravel
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- Generate unique username in Laravel