Question:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
require 'vendor/autoload.php'; use Aws\S3\S3Client; $client = S3Client::factory(array( 'key' => 'MY_KEY', 'secret' => 'MY_SECRET' )); // Register the stream wrapper from a client object $client->registerStreamWrapper(); $data = $_POST["image_data"]; list($type, $data) = explode(';', $data); list(, $data) = explode(',', $data); $data = base64_decode($data); file_put_contents('s3://webcamapp/filename.png', $data); |
This code works fine and dandy and I’m seeing my images upload to my bucket. But I need to set the ACL to public-read as I’m sending this file to S3 because I will be displaying the images on my website. I can’t figure out a way to do it using this method. Ideas?
Answer:
The S3 Stream Wrapper supports additional parameters to S3 via stream contexts. Try something like this:
1 2 3 4 5 6 7 8 |
$context = stream_context_create(array( 's3' => array( 'ACL' => 'public-read' ) )); file_put_contents('s3://webcamapp/filename.png', $data, 0, $context); |