0

I'm trying to generate a pre signed url request with the S3 PHP SDK like this:

$cmd = self::$S3Client->getCommand('GetObject', array('Bucket' => USER_CONTENT_BUCKET_NAME,'Key'    => $key));

$request = self::$S3Client->createPresignedRequest($cmd, '+20 minutes');

*USER_CONTENT_BUCKET_NAME is the bucket name defined in constants.php
*$key is string key.

If I var_dump($cmd) I can see the object is returned correctly from the getCommand().

But from the createPresignedRequest() call, I get an exception-

"Argument 2 passed to Guzzle\Service\Client::getCommand() must be of the type array, object given".

Help?

devpro
  • 16,184
  • 3
  • 27
  • 38
Jay
  • 79
  • 5

1 Answers1

1

Issue solved.

Was rather hard to catch, as the error message did not help at understanding the underlining issue.

This discussion helped a lot.

Amazon describe in their 3.x PHP api, that the way to create pre signed urls, is the way I tried above.

However, it turns out we are using version 2.8 of the Amazon aws. In this case, the call should be like this:

$cmd = self::$S3Client->getCommand('GetObject', array('Bucket' => USER_CONTENT_BUCKET_NAME,'Key' => $key));

$presignedUrl = $cmd->createPresignedUrl('+20 minutes');

The Guzzle exception thrown was a symptom of the fact that the method I was calling did not exist.

I hope this will help other stuck in the same situation.

Community
  • 1
  • 1
Jay
  • 79
  • 5