# How to use the AWS SDK for Laravel with Stook?

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:

```bash
composer require aws/aws-sdk-php-laravel
```

***

### Package Registration

Open `config/app.php` and register the package:

{% code title="Registering AWS Service Provider and AWS alias in Laravel" %}

```php
'providers' => [
    Aws\Laravel\AwsServiceProvider::class,
],

'aliases' => [
    'AWS' => Aws\Laravel\AwsFacade::class,
],
```

{% endcode %}

***

### Publish Configuration

Run the following command to publish the AWS config file:

```bash
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:

```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
    ]
];
```

***

### Define ENV Variables

Set your Stook credentials in `.env`:

```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:

```php
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

* [AWS SDK for Laravel GitHub](https://github.com/aws/aws-sdk-php-laravel)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://clients.medianova.com/products/object-storage-stook/integration-and-usage-guides/how-to-use-the-aws-sdk-for-laravel-with-stook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
