How to use the AWS SDK for PHP with Stook?
Integrate Medianova Stook Object Storage into your PHP applications using the AWS SDK.
You can connect PHP applications to Medianova Stook Object Storage using the AWS SDK for PHP. This allows you to create buckets, upload files, and retrieve objects from Stook directly in your PHP projects.
Prerequisites
PHP installed on your system
AWS SDK for PHP
Medianova Stook credentials:
Access Key
Secret Key
Endpoint
Installation
Follow AWS SDK for PHP installation guide:
Example Code
Create a PHP file and configure your Stook connection:
<?php
require 'aws/aws-autoloader.php';
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'endpoint' => 'Enter server info',
'use_path_style_endpoint' => true,
'credentials' => [
'key' => 'Enter Access Key',
'secret' => 'Enter Secret Key',
],
'http' => [
'verify' => false
]
]);
try {
$s3->createBucket(array('Bucket' => 'testbucket'));
}
catch (Exception $e){
echo "There is a bucket with that name!<br>";
}
// Sending a PutObject request and getting the results
$insert = $s3->putObject([
'Bucket' => 'testbucket',
'Key' => 'testkey',
'Body' => 'Hello world'
]);
// Download the contents of the object
$retrive = $s3->getObject([
'Bucket' => 'testbucket',
'Key' => 'testkey',
'SaveAs' => 'testkey_local'
]);
//Index the body to the result object
echo $retrive['Body'];
Example PHP code for connecting to Stook, creating a bucket, uploading and retrieving objects
Troubleshooting / FAQ
Error: “There is a bucket with that name!”
Solution: Use a unique bucket name.
Error: Connection issues
Solution: Ensure endpoint URL is correct and matches Stook.
Error: Permission denied
Solution: Validate Access Key and Secret Key.
References
Last updated
Was this helpful?