Rahul Reghunath
Rahul Reghunath

Reputation: 1276

storing files to aws s3 using laravel

Please give me an example to store files to AWS S3 in laravel 5.5. I already configured filesystem file with AWS credentials.

I saw the function

Storage::put('file.jpg', $contents);

but don't know what the second parameter is

the contents of filesystem.php file is as follows

return [


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



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


    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

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

        's3' => [
            'driver' => 's3',
            'key' => '*********',
            'secret' => '******',
            'region' => 'my region',
            'bucket' => 'bucketname',
        ],

    ],

];

thanks in advance

Upvotes: 3

Views: 11841

Answers (1)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

There is good example in Laravel documentation:

Storage::disk('s3')->put('avatars/1', $fileContents);

The 2nd parameter is is file content so in real life it could look like this:

Storage::disk('s3')->put('file.jpg', file_get_contents('your_local_file.jpg');

Upvotes: 7

Related Questions