By dangr302
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 -
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
So I figured the issue, you should remove getenv() function and use string.
use
‘key’ => ‘xxxx’, ‘secret’ => ‘xxxx’
instead of
‘key’ => getenv(‘xxxx’), ‘secret’ => getenv(‘xxxx’)
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.