简体   繁体   English

创建Amazon AWS S3预签名URL PHP时出现问题

[英]Issue creating amazon aws s3 pre signed url PHP

I'm trying to generate a pre signed url request with the S3 PHP SDK like this: 我正在尝试使用S3 PHP SDK生成一个预签名的url请求,如下所示:

$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 *USER_CONTENT_BUCKET_NAME是在constants.php中定义的存储桶名称
*$key is string key. *$key是字符串键。

If I var_dump($cmd) I can see the object is returned correctly from the getCommand() . 如果我是var_dump($cmd) ,则可以看到从getCommand()正确返回了对象。

But from the createPresignedRequest() call, I get an exception- 但是从createPresignedRequest()调用中,我得到一个异常-

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

Help? 救命?

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. 亚马逊在他们的3.x PHP api中描述了创建预签名URL的方法,这就是我上面尝试过的方法。

However, it turns out we are using version 2.8 of the Amazon aws. 但是,事实证明,我们正在使用2.8版的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. 引发的Guzzle异常是我正在调用的方法不存在的症状。

I hope this will help other stuck in the same situation. 我希望这将有助于其他陷入同样困境的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM