Question

Cannot get spaces to work with pure php

Posted August 22, 2021 84 views
PHPBlock StorageLaravelUbuntu 20.04

I always get 400 Bad Request error when I try to list via function.

require ‘vendor/autoload.php’;
use Aws\S3\S3Client;

$client = new Aws\S3\S3Client([
'version’ => 'latest’,
'region’ => 'nyc3’,
'driver’=> 's3’,
'endpoint’ => ’https://nyc3.digitaloceanspaces.com’,
'credentials’ => [
'key’ => getenv('xxxx’),
'secret’ => getenv('xxxx’),
],
]);

$spaces = $client->listBuckets();
foreach ($spaces['Buckets’] as $space){
echo $space['Name’].“\n”;
}

ERROR:

Fatal error: Uncaught exception 'Aws\S3\Exception\S3Exception’ with message 'Error executing “ListBuckets” on “https://nyc3.digitaloceanspaces.com/”; AWS HTTP error: Client error: GET https://nyc3.digitaloceanspaces.com/ resulted in a 400 Bad Request response: <?xml version=“1.0” encoding=“UTF-8”?><Error><Code>InvalidArgument</Code><RequestId>tx000000000000009191c83-006121e3ea-5 (truncated…) InvalidArgument (client): - <?xml version=“1.0” encoding=“UTF-8”?><Error><Code>InvalidArgument</Code><RequestId>tx000000000000009191c83-006121e3ea-58226b4-nyc3a</RequestId><HostId>58226b4-nyc3a-nyc</HostId></Error>’ GuzzleHttp\Exception\ClientException: Client error: GET https://nyc3.digitaloceanspaces.com/ resulted in a 400 Bad Request response: <?xml version=“1.0” encoding=“UTF-8”?><Error><Code>InvalidArgument</Code><RequestId>tx000000000000009191c83-006121e3ea-5 (truncated…) in /var/www/html/spaces/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113 Stack trace: #0 /var/www/html/spaces/vendor/guzzlehttp/ in /var/www/html/spaces/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 195

install aws with COMPOSER on my site with pure php


when I try to access with s3cmd it also generates the following error:
: 403 - AccessDenied -

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

I am getting this same thing. Any update on a solution?