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

henryoladj's avatar

Storing Images on Amazon S3 instead of local disk

On my Controller i have this but the images saves on the local disk, i want to know how i can save it on my Amazon S3

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();
        }
    }

What should be edited filesystems.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', 'local'),

    /*
    |--------------------------------------------------------------------------
    | 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' => 'local',
            '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'),
        ],

    ],

];
0 likes
6 replies
martinbean's avatar

@henryoladj You set the value of the FILESYSTEM_DRIVER environment variable to s3.

Also be sure to set values for the other S3-related environment variables (AWS_ACCESS_KEY_ID, etc).

henryoladj's avatar

It saving at my aws bucket but it still gives Image source not readable

NoTimeForCaution's avatar

If you have successfully saved an image on AWS, you can retrieve non-public assets via Storage::temporaryUrl():

return Storage::disk('s3')->temporaryUrl("/path/to/image.jpg", Carbon::now()->addMinutes(5));

Please or to participate in this conversation.