Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 1.74 KB

aws-sdk-for-php-with-minio.md

File metadata and controls

63 lines (43 loc) · 1.74 KB

How to use AWS SDK for PHP with Minio Server Gitter

aws-sdk-php is the official AWS SDK for the PHP programming language. In this recipe we will learn how to use aws-sdk-php with Minio server.

1. Prerequisites

Install Minio Server from here.

2. Installation

Install aws-sdk-php from AWS SDK for PHP official docs here

3. Example

Please replace endpoint,key, secret, Bucket with your local setup in this example.php file.

Example below shows putObject and getObject operations on Minio server using aws-sdk-php.

<?php

// Include the SDK using the Composer autoloader
date_default_timezone_set('America/Los_Angeles');
require 'vendor/autoload.php';

$s3 = new Aws\S3\S3Client([
        'version' => 'latest',
        'region'  => 'us-east-1',
        'endpoint' => 'http://localhost:9000',
        'credentials' => [
                'key'    => 'YOUR-ACCESSKEYID',
                'secret' => 'YOUR-SECRETACCESSKEY',
            ],
]);


// Send a PutObject request and get the result object.
$insert = $s3->putObject([
     'Bucket' => 'testbucket',
     'Key'    => 'testkey',
     'Body'   => 'Hello from Minio!!'
]);

// Download the contents of the object.
$retrive = $s3->getObject([
     'Bucket' => 'testbucket',
     'Key'    => 'testkey',
     'SaveAs' => 'testkey_local'
]);

// Print the body of the result by indexing into the result object.
echo $retrive['Body'];

4. Run the Program

$ php example.php
Hello from Minio!!