Last active
June 8, 2022 04:27
-
-
Save halkyon/deece82ab4f8f05e9151449b5ef32415 to your computer and use it in GitHub Desktop.
Test AWS SDK PHP v3 Storj
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 | |
// | |
// Test script to see if AWS SDK PHP works as expected with Storj gateway. | |
// | |
// Assuming a working PHP and Composer setup: | |
// | |
// 1. Copy this file to an empty dir. | |
// 2. Run `composer require aws/aws-sdk-php`. | |
// 3. Configure credentials: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html | |
// 4. Run `php index.php`. A bunch of output should show as it works through. | |
// | |
require 'vendor/autoload.php'; | |
use Aws\S3\S3Client; | |
use Aws\Credentials\CredentialProvider; | |
use Aws\Exception\AwsException; | |
$client = new S3Client([ | |
'region' => 'us-east-1', | |
'version' => '2006-03-01', | |
'endpoint' => 'https://gateway.storjshare.io', | |
]); | |
$bucket = "test-".rand(1000, 9999); | |
$result = $client->createBucket([ | |
'Bucket' => $bucket | |
]); | |
printf("Bucket created: %s\n", $result); | |
for ($i = 0; $i <= 10; $i++) { | |
$file = tmpfile(); | |
$path = stream_get_meta_data($file)['uri']; | |
for ($j = 0; $j <= 10000; $j++) { | |
fwrite($file, rand(1000, 9999)); | |
} | |
$result = $client->putObject([ | |
'Bucket' => $bucket, | |
'Key' => sprintf('test-file-%d', $i), | |
'SourceFile' => $path, | |
]); | |
fclose($file); | |
printf("Object created: %s\n", $result); | |
} | |
$result = $client->listObjects([ | |
'Bucket' => $bucket, | |
]); | |
printf("List objects: %s\n", $result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment