Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set ACL to public-read on AWS-SDK-PHP v3.2 using transfer manager

ok, my first SO question, be nice.

I am having problems finding the answer to this question. yes ive tried the options for the transfer constructor don't mention any ACL options. my searches on google come up either blank or for version 2.x this is my code

$options[] = [
'DEBUG' => true,
];
// Where the files will be transferred to
$dest = 's3://newbucket/'.$UUID;
// Create a transfer object.
$manager = new \Aws\S3\Transfer($s3, $path, $dest, $options );
// Perform the transfer synchronously.
$manager->transfer();
$promise = $manager->promise();
$promise->then(function () {
    echo 'Done!';
});

everything uploads ok but the files are not public-read where/how do i set Public-read on the files uploaded in VERSION 3.2

like image 262
StuSays Avatar asked Oct 27 '25 19:10

StuSays


1 Answers

You can add a 'before' closure to the array of options you're passing to the transfer manager that could handle assigning permissions. Try replacing your manager instantiation code with this:

$manager = new \Aws\S3\Transfer($s3, $path, $dest, [
    'before' => function (\Aws\CommandInterface $command) {
        if (in_array($command->getName(), ['PutObject', 'CreateMultipartUpload'])) {
            $command['ACL'] = 'public-read';
        }
    },
]);
like image 66
giaour Avatar answered Oct 29 '25 11:10

giaour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!