简体   繁体   中英

Amazon S3 PHP Stream Wrapper Set Public View Permissions for Image

I'm using the Amazon PHP SDK for S3 to save images to a bucket. I need to make sure that every image that gets added is publicly viewable, but I don't want to add list accessibility. I couldn't find a way to set this at the bucket level so that it propagated to all the uploaded images.

So, my question is, how do I set the permissions on the image after I move it to S3 so that it can be viewed in a browser?

My code looks like this:

require_once("aws/aws-autoloader.php");

// Amazon S3
use Aws\S3\S3Client;

// Create an Amazon S3 client object
$s3Client = S3Client::factory(array(
    'key'    => $amazonKey,
    'secret' => $amazonSecret
));

// Register the stream wrapper from a client object
$s3Client->registerStreamWrapper();

// Save Thumbnail
$s3Path = "s3://".$amazonBucket."/".$folderYear."/".$folderMonth."/";
$s3Stream = fopen($s3Path . $thumbnail, 'w');
fwrite($s3Stream,$thumb_content);
@fclose($s3Stream);

I just need help after the image has been saved, how can I make sure the image is publicly viewable but the bucket and folders do not list all the contents.

You can set this at the bucket level using bucket policies. Check out:

http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucketPolicies.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM