How to Configure ACL for Public Read on AWS-SDK-PHP v3.2 Using Transfer Manager

ok my first SO question please be nice.

I am having trouble finding the answer to this question. yes ive tried in the parameters of the migration constructor no ACL parameters are specified. my google searches appear either empty 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 fine, but files are not published where / how to install Public-read in files uploaded in version 3.2.

+3


source to share


2 answers


You can add the closure 'before'

to an array of parameters that you pass to the migration manager, which could handle the assignment of permissions. Try replacing the manager instance code with the following:



$manager = new \Aws\S3\Transfer($s3, $path, $dest, [
    'before' => function (\Aws\CommandInterface $command) {
        if (in_array($command->getName(), ['PutObject', 'CreateMultipartUpload'])) {
            $command['ACL'] = 'public-read';
        }
    },
]);

      

+2


source


One way to do this is to set bucket permissions in the console. under the permissions of the bucket you want to install. click "change cart policy"

Another piece of information you will need is creating the JSON file that you insert. http://awspolicygen.s3.amazonaws.com/policygen.html if you get an error from AWS tool just reformat it based on what you see in http://docs.aws.amazon.com/AmazonS3/ latest / dev / example-bucket-policies.html



I hope this helps others

0


source







All Articles