to read a s3 bucket file with laravel get an error

advertisements

Im trying to get file from s3 bucket using getObject

 $s3 = AWS::createClient('s3');
        $file = $s3->getObject(array(
            'Bucket' => 'hotel4cast',
            'Key'    => $path->path,
            'SaveAs' => public_path()
        ));

I'm getting below error

Error executing

"GetObject" on "https://s3.amazonaws.com/mybucket/filename.xlsx";
AWS HTTP error: Unable to open /var/www/html/laravel/public/ using mode r+: fopen(/var/www/html/laravel/public/):
ailed to open stream: Is a directory

if i take SaveAs out and dump $file i get object of data, body, stream all that stuff but not sure what to do with that.


I have figured out, there is bug in aws sdk, i was able to get file to save by storing path in var before calling getObject

$r = fopen(public_path() . '/myfile.xlsx', 'wb');

$s3 = AWS::createClient('s3');
$file = $s3->getObject(array(
   'Bucket' => 'bucketname',
   'Key'    => $path->path,
   'SaveAs' => $r
));