How to use the AWS SDK for Laravel with Stook?
Integrate Medianova Stook Object Storage into your Laravel application using the AWS SDK.
You can connect your Laravel application to Medianova Stook Object Storage by using the AWS SDK. This allows you to store and manage files directly in Stook through Laravel.
Prerequisites
Laravel project installed
Composer available on your system
Medianova Stook credentials:
Access Key
Secret Key
Endpoint
Installation
Install the AWS SDK for Laravel with Composer:
composer require aws/aws-sdk-php-laravel
Package Registration
Open config/app.php
and register the package:
'providers' => [
Aws\Laravel\AwsServiceProvider::class,
],
'aliases' => [
'AWS' => Aws\Laravel\AwsFacade::class,
],
Publish Configuration
Run the following command to publish the AWS config file:
php artisan vendor:publish --provider="Aws\Laravel\AwsServiceProvider"
This creates config/aws.php
.
Configure Stook in Laravel
Update config/aws.php
with your Stook credentials:
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
]
];
Define ENV Variables
Set your Stook credentials in .env
:
YOUR_STOOK_ACCESS_KEY_ID=xxxxxxxxxxxxxxxx
YOUR_STOOK_SECRET_ACCESS_KEY=yyyyyyyyyyyyyyyyyyyy
YOUR_STOOK_ENDPOINT=https://xxxxx.mncdn.com
Example: Upload File to Stook
Example controller method to upload files:
public function uploadStookFile(Request $request)
{
// File information
$fileExtension = $request->file('image')->getClientOriginalExtension();
$fileFullName = "testFile" . '.' . $fileExtension;
try {
$s3 = App::make('aws')->createClient('s3');
$s3->putObject([
'Bucket' => "test-bucket",
'Key' => $fileFullName,
'SourceFile' => $request->file('image')->getRealPath(),
]);
} catch (\Exception $exception) {
throw new \Exception('File could not upload to Stook account.');
}
Troubleshooting / FAQ
File not uploading: Check bucket name and credentials.
Connection error: Ensure the Stook endpoint is correct.
Permission denied: Verify Access Key and Secret Key.
References
Last updated
Was this helpful?