Search code examples
phpamazon-web-servicesamazon-s3file-exists

AWSSDK - S3 - if_object_exists keeps returning a Argument 2 passed to Guzzle error


I have a S3 bucket with 2million MP3 files inside of it and there are times when customers order a mp3 file but they are unable to download the file from our S3 bucket. Before I go and request a redelivery of the file from the content provider, I want to create a simple script that will allow me to check if the file exists in the S3 bucket. I've written a script to check the bucket, but it's I keep getting this error:

Catchable fatal error: Argument 2 passed to Guzzle\Service\Client::getCommand() must be an array, string given, called in phar:///mnt/universal_portal/prod/download/aws.phar/vendor/guzzle/guzzle/src/Guzzle/Service/Client.php on line 93 and defined in phar:///mnt/universal_portal/prod/download/aws.phar/vendor/guzzle/guzzle/src/Guzzle/Service/Client.php on line 113

This is the code I've written

require_once('appsettings.php');
require 'aws.phar';

use Aws\S3\S3Client;

$client = S3Client::factory(array(
   'key'    => $aws_key,
   'secret' => $aws_secret
));

$filename = '000002422704.mp3' . strtolower($aws_key);
$info = $client->if_object_exists($aws_bucket,$filename);

return $info;

I've been going off this Amazon link, but I can't get this file check to work.

Any help is greatly appreciated.

Cheers


Solution

  • The link you posted is for SDK 1.x. The Phar file and the instantiation you're using is for SDK 2.x. They both need to be the same version. :)

    You're looking for Aws\S3\S3Client::doesObjectExist() in SDK 2.x.