[RESOLVED] Upload base64 data url file to AWS S3 in Laravel

Rabib Galib
1 min readOct 16, 2023

--

Step 1: configure S3 Driver

Install the Flysystem S3 package via the Composer package manager

composer require league/flysystem-aws-s3-v3 "^3.0"

Step 2: Laravel end configuration

In laravel end, there’s two options to configure credentials for S3.

1. .env
2. config/filesystem.php // If we check this file, this mainly calls the .env variables.

We’ll set values in the .env file

AWS_ACCESS_KEY_ID=XXXXXX
AWS_SECRET_ACCESS_KEY=XXXXXXXX
AWS_DEFAULT_REGION=us-east-2
AWS_BUCKET=MY_AWS_BUCKET
AWS_USE_PATH_STYLE_ENDPOINT=false
AWS_URL=MY_AWS_URL

The config/filesystem.php file be like

return [
'disks' => [
'local' => [
// local configuration here
],
'public' => [
// public configuration here
],
'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'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
],
],
];

Step 3: Now put below code to your functionality

That’s All. Have fun 🔥 💪

If you have any query, please put in below. Find me on Github.

--

--

Rabib Galib

Senior Software Engineer, Masters in Computer Science & Engineering, PHP, Python, Chatbot Expert, AI Research