Created
January 2, 2019 11:28
-
-
Save mhemrg/83d937ba743056b39f550e540eb93caf to your computer and use it in GitHub Desktop.
Example below shows putObject and getObject operations on Liara using aws-sdk-php. Please replace endpoint,key, secret, Bucket with your local setup in this example.php file. Note that we set use_path_style_endpoint to true to use Liara with AWS SDK for PHP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' => 'https://asdfasdf.storage.liara.ir', | |
'use_path_style_endpoint' => true, | |
'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 Liara!!' | |
]); | |
// 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']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment