Unable to upload file in s3 bucket using laravel 5.7- Argument 1 passed to League\Flysystem\AwsS3v3\AwsS3Adapter:

强颜欢笑 提交于 2021-01-28 04:58:55

问题


I am trying to upload the image to the s3 bucket but unable to do so. Getting the following error:

Storage::disk('s3')->put($filename, file_get_contents($file));

Argument 1 passed to League\Flysystem\AwsS3v3\AwsS3Adapter::__construct() must be an instance of Aws\S3\S3ClientInterface, instance of Aws\S3\S3Client given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php on line 208 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Argument 1 passed to League\\Flysystem\\AwsS3v3\\AwsS3Adapter::__construct() must be an instance of Aws\\S3\\S3ClientInterface, instance of Aws\\S3\\S3Client given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php on line 208 at /var/www/html/vendor/league/flysystem-aws-s3-v3/src/AwsS3Adapter.php:85)

My composer.json contains:

...
"aws/aws-sdk-php": "3.0",
"laravel/framework": "5.7.*",
"league/flysystem-aws-s3-v3": "~1.0",
"league/flysystem-cached-adapter": "1.0",
...

My filesystems.php

 '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'),
        ],

AWS s3 user permission - AmazonS3FullAccess

AWS s3 bucket - policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicRead",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject",
                "s3:GetObjectVersion",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::[bucket-name]/*"
        }
    ]
}

Any help would be highly appreciated.

Thanks


回答1:


After struggling for more than 4 days, I removed both "aws/aws-sdk-php": "3.0", and "league/flysystem-aws-s3-v3": "~1.0", "league/flysystem-cached-adapter": "1.0", from composer.json and run composer require league/flysystem-aws-s3-v3

After that, it worked :)



来源:https://stackoverflow.com/questions/64193773/unable-to-upload-file-in-s3-bucket-using-laravel-5-7-argument-1-passed-to-leagu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!