Question: > 
> Since Digital Ocean Spaces API is compatible with AWS SDK, how to
>  upload images to Digital Ocean Spaces programmatically using AWS SDK
>  for Yii2?
> 
> 
> 

Here my details

```
Good, we have the following data: 
1. endpoint: fra1.digitaloceanspaces.com
2. bucket name: dev-abc
3. api key: xxxxxxxxxxxxx and api secret: xxxxxxx
4. The url that you need to use to deliver assets is https://dev-abc

```

I have tried with this code whis is not working

```
$uploader = new FileUpload(FileUpload::S_S3, [
    'version' => 'latest',
    'region' => 'fra1',
    'endpoint' => 'https://fra1.digitaloceanspaces.com',
    'credentials' => [
        'key' => 'xxxxxxxxxxxxx ',
        'secret' => 'xxxxxxx'
    ],
    'bucket' => 'dev-abc'
]);

```

Answer: 
You can php code to upload image in digital ocean:

1. Configure a client:

use Aws\S3\S3Client;

```
$client = new Aws\S3\S3Client([
    'version' => 'latest',
    'region'  => 'us-east-1',
    'endpoint' => 'https://nyc3.digitaloceanspaces.com',
    'credentials' => [
        'key'    => getenv('SPACES_KEY'),
        'secret' => getenv('SPACES_SECRET'),
    ],
]);

```
2. Create a New Space

```
$client->createBucket([
    'Bucket' => 'example-space-name',
]);

```
3. Upload Image

```
$client->putObject([
    'Bucket' => 'example-space-name',
    'Key'    => 'file.ext',
    'Body'   => 'The contents of the file.',
    'ACL'    => 'private'
]);

```
Install composer from <https://getcomposer.org/download/> and then run the following to setup the AWS PHP dependencies:

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

```

The following code has a form for uploading images, the code processes the files and uploads them to DO Spaces. Replace your values with those in the code.

```
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;

        if(isset($_FILES['image'])){
            $file_name = $_FILES['image']['name'];   
            $temp_file_location = $_FILES['image']['tmp_name']; 

            $s3 = new Aws\S3\S3Client([
                'region'  => '-- your region --',
                'version' => 'latest',
                'credentials' => [
                    'key'    => "-- access key id --",
                    'secret' => "-- secret access key --",
                ]
            ]);     

            $result = $s3->putObject([
                'Bucket' => '-- bucket name --',
                'Key'    => $file_name,
                'SourceFile' => $temp_file_location         
            ]);

            var_dump($result);
        }
    ?>

    <form action="<?= $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">         
        <input type="file" name="image" />
        <input type="submit"/>
    </form>

```