NoLAstNamE's avatar

Flysystem Argument #1 ($client) must be of type Aws\S3Client

I'm using league/flysystem-aws-s3-v3 ^1.0 package to upload my images on DigitalOcean Spaces and I got the error below when I try to trigger the upload.

League\Flysystem\AwsS3v3\AwsS3Adapter::__construct(): Argument #1 ($client) must be of type Aws\S3Client, Aws\S3\S3Client given, called in /home/forge/site.com/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php on line 229

composer.json

"laravel/framework": "^8.65",
"league/flysystem-aws-s3-v3": "1.0",

.env

SPACES_ACCESS_KEY_ID=xxxxx
SPACES_SECRET_ACCESS_KEY=xxxxxxx
SPACES_DEFAULT_REGION=sgp1
SPACES_BUCKET=avatar
SPACES_ENDPOINT=sgp1.digitaloceanspaces.com
SPACES_PUBLIC=https://xxx-xxx.sgp1.digitaloceanspaces.com

filesystems.php

'spaces' => [
    'driver' => 's3',
    'key' => env('SPACES_ACCESS_KEY_ID'),
    'secret' => env('SPACES_SECRET_ACCESS_KEY'),
    'region' => env('SPACES_DEFAULT_REGION'),
    'bucket' => env('SPACES_BUCKET'),
    'url' => env('SPACES_PUBLIC'),
    'endpoint' => env('SPACES_ENDPOINT'),
    'bucket_endpoint' => true,
    'visibility' => 'public',
],

Controller

use Illuminate\Support\Facades\Storage;


$user = Auth::user();
$filePath = Storage::disk('spaces')
    ->putFile('avatars/user-'.$user->id, $request->image, 'public');
$user->avatar = env('SPACES_PUBLIC').$filePath;
$user->save();

0 likes
13 replies
NoLAstNamE's avatar

@Tray2 Thank you, I see that the this is my workaround

  1. Add "league/flysystem-aws-s3-v3": "^1.0", in composer.json and run composer update
  2. Update .env's SPACES_ENDPOINT to the same value as SPACIES_PUBLIC
Sinnbeck's avatar

Never use env outside of config files!

$user->avatar = env('SPACES_PUBLIC').$filePath;
//should be something like 
$user->avatar = config('storage.spaces.url') .$filePath;
//or even better. Don't store the url at all, and use storage to resolve it you need it
$user->avatar = $filePath;
1 like
Sinnbeck's avatar

Wasn't it the answer by @tray2 that solved the issue? Mine was just a tip to save yourself from trouble later on

1 like

Please or to participate in this conversation.