devinfd's avatar

flysystem error with s3 api

After updating to 5.1 and updating league/flysystem-aws-s3-v3 to ~1.0 I am getting this error when trying to upload a file to s3.

InvalidArgumentException in AwsClient.php line 77: api is a required option

And before you ask it, yes I do have an api key and secret set up in the config file. I'm at a loss as to why this error is happening. Does anybody have a clue?

0 likes
3 replies
jimmck's avatar

HI, I have been having a lovely evening with the new AWS version 3. I have code for AWS directly and League/AWS. I had problems installing 5.1 with previous version of League. So I took it out and it worked. Updated AWS 3.0 and my AWS Non-League code to upload files broke. So I made some api changes and had to add a new environment variable. If you have Zend Opcache turned on, it writes files to a PHP temp file. Got permission issues. So I set the new env var in .env to point to the storage dir Laravel uses.

    \Route::get('lissa', function () {
        print 'HHHHHHHHHHHHHH';
        $s3 = \AWS::createClient('s3');
        //$s3 = AWS::get('s3');
        $result = $s3->putObject(array ('Bucket' => 'jimmck-holmdel', 'Key' => 'melissa.txt', 'Body' => 'Hi!!!!!',));
        echo $result['Expiration'] . "\n";
        echo $result['ServerSideEncryption'] . "\n";
        echo $result['ETag'] . "\n";
        echo $result['VersionId'] . "\n";
        echo $result['RequestId'] . "\n";
        // Get the URL the object can be downloaded from
        echo $result['ObjectURL'] . "\n";
    });

The comment line is the change for native AWS SDK call.

The .env setting is

AWS_PHP_CACHE_DIR=/Users/jimm/GitHub/laravel5/storage/aws

Saw your post and added league back to my composer.json and didm an update. Got version 1.02

My league code ran fine with update. I looked at line 77 in AWSClient and its part of a giant comment. Usually in the past arg errors in the SDK are either creds or service settings like 's3' ... Do, you have a stack trace. Like I said my creds for the league are in filesystem.php.

my working league code is ''' \Route::get('files', function () { // Get a remote list of files. $disk = \Storage::disk('s3'); $files = $disk->allFiles(); print ""; foreach ($files as $file) { $modified = date(DATE_RFC2822, $disk->lastModified($file)); $size = $disk->size($file); $type = $disk->mimeType($file); print "

  • $file : $modified ($size Bytes) : $type
  • "; } print ""; });

    
    and the output is as expected
    
    

    backups/20150509021034.zip : Sat, 09 May 2015 02:10:36 +0000 (232 Bytes) : binary/octet-stream backups/20150509021212.zip : Sat, 09 May 2015 02:12:14 +0000 (232 Bytes) : binary/octet-stream data.txt : Fri, 27 Mar 2015 04:05:10 +0000 (6 Bytes) : binary/octet-stream melissa.txt : Tue, 16 Jun 2015 06:04:08 +0000 (7 Bytes) : application/octet-stream

    
    
    jimmck's avatar

    Sorry league code is...

        \Route::get('files', function () {
            // Get a remote list of files.
            $disk = \Storage::disk('s3');
            $files = $disk->allFiles();
            print "<div>";
            foreach ($files as $file) {
                $modified = date(DATE_RFC2822, $disk->lastModified($file));
                $size = $disk->size($file);
                $type = $disk->mimeType($file);
                print "<li> $file : $modified ($size Bytes) : $type</li>";
            }
            print "</div>";
        });
    
    
    devinfd's avatar

    @jimmck Thanks for your hep but I discovered that the problem was that composer was downloading aws/aws-sdk-php version 3.0.0-beta.1. I then found

    "minimum-stability": "dev",
    "prefer-stable": true
    

    in my composer file, removed that, updated composer and wah lah, everything works now.

    Please or to participate in this conversation.