demonz's avatar

Did amazon update their s3 storage setting ?

hello i spent like 7 hours , i was following some tutorial in yt how to upload to amazon s3, but the problem that the file uploaded visibility is always private and when i try to upload it as public it doesn't upload and ddd() return false the guy i was following his steps , first he created a bucket then unchecked the block public access and added 'visibility' => 'public' to the s3 disk in filesystem.php , and everything works for him , but for me 'visibility' => 'public' didn't work so i tried storePubliclyAs and putFile with public parameter and also didn't work , the visibility must be private to be uploaded to the bucket , how is that ? do i need to change something else than unchecking the block public access in amazon s3? or the issue is related to laravel 9 which i don't think so , help please

0 likes
2 replies
LaryAI's avatar
Level 58

It's possible that Amazon has updated their S3 storage settings, but it's also possible that there's an issue with your code or configuration. Here are a few things you can try:

  1. Double-check that you've unchecked the "Block public access" setting for your S3 bucket. This is necessary to allow public access to your files.

  2. Make sure that you're setting the correct ACL (Access Control List) when uploading your files. The ACL determines who has access to the file. To upload a file with public access, you should set the ACL to "public-read". Here's an example:

Storage::disk('s3')->put('filename.txt', $contents, 'public');
  1. If setting the ACL doesn't work, try setting the "visibility" option to "public" when configuring your S3 disk in Laravel. Here's an example:
's3' => [
    'driver' => 's3',
    'key' => 'your-key',
    'secret' => 'your-secret',
    'region' => 'your-region',
    'bucket' => 'your-bucket',
    'visibility' => 'public',
],
  1. If none of the above solutions work, try using the AWS SDK directly to upload your files. Here's an example:
use Aws\S3\S3Client;

$client = new S3Client([
    'version' => 'latest',
    'region' => 'your-region',
    'credentials' => [
        'key' => 'your-key',
        'secret' => 'your-secret',
    ],
]);

$result = $client->putObject([
    'Bucket' => 'your-bucket',
    'Key' => 'filename.txt',
    'Body' => $contents,
    'ACL' => 'public-read',
]);

if ($result['@metadata']['statusCode'] === 200) {
    // File uploaded successfully
} else {
    // Error uploading file
}

Hopefully one of these solutions will work for you!

demonz's avatar
demonz
OP
Best Answer
Level 2

worked after configuring ACLs , but then I disabled then ACLs and use bucket policy to enable public read only for certain objects better than making the entire bucket public

Please or to participate in this conversation.