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
- SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'posts_user_id_foreign'; check that column/key exists
- If condition in foreach loop in laravel
- How to add a key value pair to existing array in laravel
- File_put_contents(/var/www/html/w3code/storage/framework/sessions/CXwN3EXKxERD6jgy3rADcaAAbAx8FRKih2JK7UO9): Failed to open stream: Permission denied
- Return redirect laravel not working
- Method Illuminate\Events\Dispatcher::fire does not exist
- Undefined property: stdClass::$title
- How to customize or Change validation error messages
- Update email with unique validation in laravel
- Json encode method in laravel
- Print last executed query in laravel
- Composer create project laravel/laravel example app
- Sample .htaccess file and index.php file under public directory in laravel
- How to update record after save method in Laravel
- How to return a column with different name in Laravel
- Retain selected value of select box in Laravel
- Validation for multiple forms on same page in laravel
- Post model with title and body in laravel 8
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- How to show data by ID in laravel?
- How to pass two variables in HREF in laravel
- Conditional where clause in Laravel
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- How to get date from created_at field in laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()