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!
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.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
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!