Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Danlog's avatar

Access denied when trying to retrieve image from Amazon S3

After successfully uploading an image, I'm now trying to get the image from s3.

I'm doing so the following way:

<img src="{{Storage::disk('s3')->url($course->featured_image)}}" alt="course">

I'm getting the URL correctly (same one I see in AWS). The issue is that the image does not display, but it's actually stored in the bucket. I tried accessing the URL, and said access denied.

Where did I go wrong here?

0 likes
9 replies
martinbean's avatar

@danlog The object (image) is probably private. Try generated a temporary signed URL for the image instead.

martinbean's avatar

@Danlog It’s not. You can’t just view non-public files. And the IAM user the access key and secret key belongs to needs the GetObject permission to be able to generate signed URLs for private objects. If you don’t satisfy either of those requirements, then you’ll get Access Denied errors because, well, access is denied.

Danlog's avatar

@martinbean hm...? The permissions are set to full access.

inside the JSON we can see what's happening:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:*",
                "s3-object-lambda:*"
            ],
            "Resource": "*"
        }
    ]
}

screenshot: https://imgur.com/a/X4lGkaJ

Snapey's avatar

@Danlog The policy is for the IAM user accessing the bucket. Not public access.

Snapey's avatar

look at the files in the bucket, it will tell you if it's publicly accessible

lat4732's avatar

How did you uploaded this image? Through the dashboard or through Laravel code?

Danlog's avatar

@Laralex code.

Here it is:

        $file = $request->featured_image;
        $filename = time().'.'.$request->featured_image->extension();
        $file->storeAs('images/', $filename, 's3');

        $course = Course::create([
            'featured_image' => $filename,
        ]);
lat4732's avatar

@Danlog Try using this

$file = $request->featured_image;
$filename = time().'.'.$request->featured_image->extension();

Storage::disk('s3')->put("images/" . $filename, $file, 'public');

$course = Course::create([
      'featured_image' => $filename,
]);

Please or to participate in this conversation.