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

henryoladj's avatar

Image source not readable (what am i doing wrong)

I am trying to store my images on Aws and show it on my blog page.

immediately i post with images it shows this Image source not readable but the image is saved on aws.

Controller

private function storeImage($post)
    {
        if (request()->hasFile('image')){

            $original = request()->file('image')->getClientOriginalName();

            $post->update([
                'image' => request()->file('image')->storeAs('uploads', $original),
            ]);

            $image = Image::make(public_path('image/'. $post->image));
            $image->save();
        }

Filesystem.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Filesystem Disk
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default filesystem disk that should be used
    | by the framework. The "local" disk, as well as a variety of cloud
    | based disks are available to your application. Just store away!
    |
    */

    'default' => env('FILESYSTEM_DRIVER', 's3'),

    /*
    |--------------------------------------------------------------------------
    | Default Cloud Filesystem Disk
    |--------------------------------------------------------------------------
    |
    | Many applications store files both locally and in the cloud. For this
    | reason, you may specify a default "cloud" driver here. This driver
    | will be bound as the Cloud disk implementation in the container.
    |
    */

    'cloud' => env('FILESYSTEM_CLOUD', 's3'),

    /*
    |--------------------------------------------------------------------------
    | Filesystem Disks
    |--------------------------------------------------------------------------
    |
    | Here you may configure as many filesystem "disks" as you wish, and you
    | may even configure multiple disks of the same driver. Defaults have
    | been setup for each driver as an example of the required options.
    |
    | Supported Drivers: "local", "ftp", "sftp", "s3"
    |
    */

    'disks' => [

        'local' => [
            'driver' => 's3',
            'root' => public_path('image/'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

    ],

];

Blade

<img class="post-image rectangle" src="{{ secure_asset('image/' . $post->image ) }}">

What am i doing wrong?

0 likes
20 replies
NoTimeForCaution's avatar

Appears as if you're using Intervention Image and AWS:

$image = Image::make(request()->file('photo'));
Storage::disk('s3')->put("/path/toAws/Image.jpg", $image->stream());
henryoladj's avatar

@notimeforcaution it is saving now and it is updated in my database but it is not displaying on the website so i added this

$image = Image::make(request()->file('image'));
            Storage::disk('s3')->put("uploads", $image->stream());
            return Storage::disk('s3')->temporaryUrl("uploads", Carbon::now()->addMinutes(5));

It is giving this error Class 'Carbon' not found

also how can i display it on the blade

<img class="post-image rectangle" src="{{ secure_asset('image/' . $post->image ) }}">

it is storing as uploads\image.jpg in the database

NoTimeForCaution's avatar

Import Carbon within controller with:

use Carbon\Carbon;

And display Storage instance in your blade templates as a regular variable unless you want to store locally:

$image = Storage::disk('s3')->temporaryUrl("uploads", Carbon::now()->addMinutes(5));
<img src="{{ $image }}"/>
henryoladj's avatar

@notimeforcaution anytime i visit the image url e.g localhost:8000/images/uploads/image.jpg it usually says NOT FOUND the image saves in the database and also at S3

Controller

private function storeImage($post)
    {
        if (request()->hasFile('image')){

            $original = request()->file('image')->getClientOriginalName();

            $post->update([
                'image' => request()->file('image')->storeAs('uploads', $original),
            ]);

            $image = Image::make(request()->file('image'));
            Storage::disk('s3')->put('uploads', $image->stream());
            $image = Storage::disk('s3')->temporaryUrl("uploads", Carbon::now()->addMinutes(5));
        }
    }
Sinnbeck's avatar

Shouldn't it load the image from s3?

Something like

<img class="post-image rectangle" src="{{ Storage::disk('s3')->url('image/'. $post->image ) }}">
NoTimeForCaution's avatar

What @sinnbeck posted will work as well.

I cache all images via controller method calls but simply returning the s3 url works as well. The image may have to be made public via AWS bucket console though. Can't recall.

@henryoladj Is your Storage instance returning path to files in tinker? Start a tinker session and try:

Storage::disk('s3')->allFiles('/uploads');

It should return array of string values of all files in the instance.

Sinnbeck's avatar

How about returning the raw data with a header?

return response(Storage::disk('s3')->get($image))->header('Content-Type', 
           'image/jpeg');
NoTimeForCaution's avatar

@henryoladj

You absolutely can but will probably get AccessDenied from AWS until you make the image public.

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>07CFF9F017D3BC42</RequestId>
<HostId>
uALdk71Q0CLN7giHKSTQ8/w/N19DJ1L+73zY6YH8sagcUM8htVdcXyF0quk1hzZLysZj48sFuvQ=
</HostId>
</Error>

Do you know how to do that?

Sinnbeck's avatar

And you are absolutely sure that $image is the path to the image on s3? Try dd($image);

Sinnbeck's avatar

Ok that is an url, not a path. try setting it manually. Like

$image = 'path/to/image.jpg';
Sinnbeck's avatar

Yes just remove the dd. It was just for debugging. And change the path to one you know exists

henryoladj's avatar

@notimeforcaution @sinnbeck I have created the aws account and linked it on my laravel, the images are storing inside aws and also in my database.

but i do not want to use aws url but my own website url to access the image like so ````localhost:8000/images/uploads/image.jpg```

private function storeImage($post)
    {
        if (request()->hasFile('image')){

            $original = request()->file('image')->getClientOriginalName();

            $post->update([
                'image' => request()->file('image')->storeAs('uploads', $original),
            ]);

            $image = Image::make(request()->file('image'));
            Storage::disk('s3')->put('uploads', $image->stream(), 'public');
            $image = Storage::disk('s3')->temporaryUrl("uploads", Carbon::now()->addMinutes(5));
            $image = 'http://localhost:8000/images/';
        }
    }

I want this image link to change from the one below

@if($post->image)
        <img class="post-image rectangle" src="{{ secure_asset('https://example-bucket.s3.eu-west-2.amazonaws.com/' . $post->image ) }}">
        @endif

to something like this

@if($post->image)
    <img class="post-image rectangle" src="{{ secure_asset('images/' . $post->image ) }}">
@endif

which displays an image link like this http://localhost:8000/images/uploads/image.jpg

mind you image is stored in my database like uploads/image.jpg

Snapey's avatar

whilst technically possible, I don't believe you have the experience to pull it off.

You would need to create a route which accepts the image request, gets the correct image from AWS then returns it to the visitor.

This process will be slower than just using local storage.

Your url in the database is the least of your issues

Please or to participate in this conversation.