How to use the AWS SDK for Laravel with Stook?
To use the Laravel SDK, follow the steps below.
- Install the AWS SDK for Laravel.
- Register package to your application
- Configure AWS profiles for the Stook account using the Stook keys.
Installation
You can use the composer to install the AWS SDK for your Laravel application
composer require aws/aws-sdk-php-laravel
Package Registration
After installation, you must register the package usage for your application via the config/app.php
'providers' => [ // ... Aws\Laravel\AwsServiceProvider::class, ]
'aliases' => [ // ... 'AWS' => Aws\Laravel\AwsFacade::class, ]
Stook Configuration
Run vendor publish command on your terminal. This command will create config/aws.php file. You can use this file to configure your stook account with your application
php artisan vendor:publish —provider="Aws\Laravel\AwsServiceProvider"
After publish, edit the config/aws.php.
return [ 'credentials' => [ 'key' => env(‘YOUR_STOOK_ACCESS_KEY_ID'), 'secret' => env(‘YOUR_STOOK_SECRET_ACCESS_KEY'), ], 'region' => env('YOUR_STOOK_REGION', 'us-east-1'), 'version' => 'latest', 'ua_append' => [ 'L5MOD/' . AwsServiceProvider::VERSION, ], 'endpoint' => env('YOUR_STOOK_ENDPOINT'), 'use_path_style_endpoint' => true, 'http' => [ 'verify' => false ] ];
You must define your ENV variables via the .env file.
Usage
public function uploadStookFile(Request $request) { // File Informations $fileExtension = $request->file(‘image') ->getClientOriginalExtension(); $fileFullName = "testFile". '.' . $fileExtension; // Try upload file to Stook try { $s3 = App::make('aws')->createClient('s3'); $s3->putObject(array( 'Bucket' => "test-bucket", 'Key' => $fileFullName, 'SourceFile' => $request->file('image')->getRealPath(), )); }catch (\Exception $exception){ throw new \Exception('File could not upload to stook account.'); } }
If you have a problem with your account or application, you can email support@medianova.com or reach our support team by phone at +90 212 275 5456.