Laravel 5 amazon s3 file upload tutorial - Part 1By Hardik Savani | January 4, 2017 | | 70509 Viewer | Category : PHP Laravel Bootstrap Amazon API
Today, I am going to share with you How to file upload in AWS s3 using Laravel 5. Laravel 5 introduce new feature in FileSystem that makes easy to upload file or image or docs etc in S3 server.
If you plane to keep your files like image, docs(pdf, xlx, docs), video or audio files on Amazon S3 server and access like CDN. So Laravel 5 FileSystem provide to simple way to upload files in amazon s3 server and also get easily file url and remove it etc. In this tutorial we will go through full example of image upload in s3 server from scratch.
When we use s3 driver for Storage FileSystem we require to install "league/flysystem-aws-s3-v3" composer package for amazon api. So you have to just follow few step to do this from scratch.
Let's start for make example of image upload in s3 server from Laravel 5.3.
Step 1 : Install Laravel Fresh Application
we are going from scratch, So we require to get fresh Laravel application using bellow command, So open your terminal OR command prompt and run bellow command:
composer create-project --prefer-dist laravel/laravel blog
Step 2: Install flysystem-aws-s3-v3 Package
In this step we have to flysystem-aws-s3-v3 package for amazon api access. We require this package because this package will provide amazon file system api, So one your cmd or terminal and fire bellow command:
composer require league/flysystem-aws-s3-v3
Step 3 : Amazon S3 Server Configuration
In this step, we require to make your amazon s3 server configuration, you have to add following details on your filesystems.php file.
In filesystems.php file also available array for this details, make sure your details is correct. you can configure all details as in your system, So you can put like as bellow:
disks => [
's3' => [
'driver' => 's3',
'key' => 'your-key',
'secret' => 'your-secret',
'region' => 'your-region',
'bucket' => 'your-bucket',
Step 4: Create Route
In this is step we need to create route for s3 image upload layout file and another one for post request. so open your routes/web.php file and add following route.
Ok Now we will see last two step in next page, so click on bellow button.