I’ve tried using this SDK and then again directly with the S3 SDK but so far I’ve been unable to set a file’s privacy to public after upload, nor change the space’s (bucket) privacy to public.

Trying to set a file’s privacy to public always returns a 404, despite the file being successfully uploaded and the path correct. Setting the space to public doesn’t give an error but doesn’t seem to have an effect on any directory or file inside it.

Here is the code I’m using

$client = new Aws\S3\S3Client([
  'version' => 'latest',
  'region'  => 'us-east-1',
  'endpoint' => getenv('storage.region'),
  'credentials' => [
    'key'    => getenv('storage.access_key'),
    'secret' => getenv('storage.secret_key'),
  ]
]);

$client->uploadDirectory($filePath, "XX", $dirName); // successful
$client->putBucketAcl(["Bucket" => "XX", "ACL" => 'public-read']); // no error, but no effect on space

foreach (new DirectoryIterator($filePath) as $file) {
  if($file->isDot()) continue;
  $client->putObjectAcl(["Bucket" => "XX", "Key" => $dirname . $file->getFilename(), "ACL" => "public-read"]); // always returns 404
}

Unlike another question posted here there are no special characters in the filenames nor the paths used, here is one example:

https://xx.nyc3.digitaloceanspaces.com/media/pages/journal/11-27-2020/3551000373-1607742797/m6-75-29a-100x.jpg
Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!