I’m trying to delete objects useing CURL,
I’v made some changes on this code: https://www.digitalocean.com/community/questions/digitalocean-spaces-file-upload-using-curl
But I get this error:
SignatureDoesNotMatch
Please have a look on my code here and see if you can help to solve this issue.
$file = "cat.jpg";
$accessKeyId = '**********';
$secretKey = '***************';
$longDate = gmdate('Ymd\THis\Z');
$shortDate = gmdate('Ymd');
$cannonical = 'DELETE'.'host:bucket.sgp1.digitaloceanspaces.com'.PHP_EOL.'x-amz-date:'.$longDate.''.PHP_EOL.'content-length;host;x-amz-content-sha256;x-amz-date';
$cannonical = hash('sha256', $cannonical);
$string = 'AWS4-HMAC-SHA256'.PHP_EOL.''.$longDate.''.PHP_EOL.''.$shortDate.'/sgp1/s3/aws4_request'.PHP_EOL.''.$cannonical;
$signingKey = hash_hmac('sha256', $shortDate, 'AWS4'.$secretKey, true);
$signingKey = hash_hmac('sha256', 'sgp1', $signingKey, true);
$signingKey = hash_hmac('sha256', 's3', $signingKey, true);
$signingKey = hash_hmac('sha256', 'aws4_request', $signingKey, true);
$signature = hash_hmac('sha256', $signingKey.$string, $signingKey);
$signature = hash_hmac('sha256', $string, $signingKey);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_URL, 'https://bucket.sgp1.digitaloceanspaces.com/'.$file);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Host: bucket.sgp1.digitaloceanspaces.com',
'Authorization: AWS4-HMAC-SHA256 Credential='.$accessKeyId.'/'.$shortDate.'/sgp1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature='.$signature
]);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POSTFIELDS, $file);
$result = curl_exec($ch);
curl_close($ch);
Thanks heaps.
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!
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.