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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.