Hello community!
I was following several topics all around the internet, but starting by this one : https://docs.digitalocean.com/products/spaces/reference/s3-sdk-examples/
For background info:
Issue 1: If I upload a document without specifying the ACL then it’s not accessible in read only by unknown users.
Issue 2: If I put ACL attribute in URL generation, then I’m getting a “SignatureDoesNotMatch” as response.
I’m a bit lost on this topic… Any help would be very appreciated
Here is some code I’m using :
private function generatePreSignedURL($type, $extension): string
{
$data = [
'credentials' => [
'key' => $this->awsKey,
'secret' => $this->awsSecret,
], 'region' => $this->awsRegion,
'version' => 'latest',
'use_path_style_endpoint' => false,
];
if ($this->awsEndpoint) {
$data['endpoint'] = $this->awsEndpoint;
}
$s3Client = new S3Client($data);
$cmdArgs = [
'Bucket' => $this->awsBucket,
'Key' => $this->generateKeyObject($type, $extension), // Defines in which folder the file will be stored
'ACL' => 'public-read' // If I remove this, upload works... But unable to read
];
$cmd = $s3Client->getCommand('PutObject', $cmdArgs);
$request = $s3Client->createPresignedRequest($cmd, $this->awsUrlLifeTime);
return (string) $request->getUri();
}
And here is the policy.json file i’ve uploaded to my bucket :
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::the-bucket/*"
}
]
}
Where am I missing something? :D
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!
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.