By Dev Lexicon
Hello,
I’m receiving the following error whenever I try to upload files to my DigitalOcean Spaces by way of the AWS SDK on PHP.
Fatal error: Uncaught exception ‘Aws\S3\Exception\S3Exception’ with message ‘Error executing “PutObject” on “https://SPACES.sfo2.digitaloceanspaces.com/FILEPATH/FILENAME.EXT”; AWS HTTP error: Client error: PUT https://SPACES.sfo2.digitaloceanspaces.com/FILEPATH/FILENAME.EXT
resulted in a 403 Forbidden
response: <?xml version=“1.0” encoding=“UTF-8”?><Error><Code>SignatureDoesNotMatch</Code><RequestId>tx000000000000084eb6bea-005e97 (truncated…) SignatureDoesNotMatch (client): - <?xml version=“1.0” encoding=“UTF-8”?><Error><Code>SignatureDoesNotMatch</Code><RequestId>tx000000000000084eb6bea-005e9740a7-443fd0-sfo2a</RequestId><HostId>443fd0-sfo2a-sfo</HostId></Error>’ GuzzleHttp\Exception\ClientException: Client error: PUT https://SPACES.sfo2.digitaloceanspaces.com/FILEPATH/FILENAME.EXT
resulted in a 403 Forbidden
response: <?xml version=“1.0” encoding=“UTF-8”?><Error><Code>SignatureDoesNotMatch</Code><RequestId>tx000000000000084eb6bea-005e97 (t in /var/www/vhosts/SUBSCRIPTION/DOMAIN/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 195
Here’s my code:
###spaces_config.php
require '../../vendor/autoload.php';
use Aws\S3\S3Client;
$spaces = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-west',
'endpoint' => 'https://sfo2.digitaloceanspaces.com',
'credentials' => [
'key' => 'SPACES_KEY',
'secret' => 'SPACES_SECERT_KEY',
],
]);
###spaces_UPLOADBLADE.php
$spaces->putObject([
'Bucket' => 'SPACES',
'Key' => 'FILEPATH ON SPACES.$fileKey,
'Body' => fopen($fileTemp, 'r'),
'ContentType' => 'image/'.$fileExtension,
'ACL' => 'private'
]);
###databaseUpload.php file that when form is submitted goes to
$fileFile = $_FILES['fileFile'];
$fileName = $_FILES['fileFile']['name'];
$fileTemp = $_FILES['fileFile']['tmp_name'];
$fileSize = $_FILES['fileFile']['size'];
$fileError = $_FILES['fileFile']['error'];
$fileType = $_FILES['fileFile']['type'];
$fileExplode = explode('.', $fileName);
$fileExtension = strtolower(end($fileExplode));
$thumbnailExtAllow = array('jpg', 'jpeg', 'png', 'pdf');
$thumbnailKey = $postID.".".$fileExtension;
include '../../do_spaces/spaces_config.php';
include '../../do_spaces/spaces_UPLOADBLADE.php';
If anyone is able to help I would greatly appreciate it!
Thanks, DevLexicon
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!
Accepted Answer
RESOLVED!
So after much digging I realized I was using a “Personal access tokens” for the secret key and not having a generated Spaces secret key.
Thus I regenerated the key and it worked!
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.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.