AWS S3 PHP getObject标准示例导致致命错误

时间:2013-10-01 15:20:24

标签: php amazon-web-services amazon-s3 fatal-error method-call

我有一些看起来完全像这样的代码:

$result = $client->getObject(array(
   'Bucket' => $bucket,
   'Key'    => 'data.txt',
   'SaveAs' => '/tmp/data.txt'
));

此处列出的示例之一:http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.S3.S3Client.html#_getObject

不幸的是我得到了这个致命的错误:

PHP Warning:  Missing argument 2 for AmazonS3::get_object() in /var/www/CronJobs/aws-sdk-    for-php/services/s3.class.php on line 1489
PHP Notice:  Undefined variable: filename in /var/www/CronJobs/aws-sdk-for-php/services/s3.class.php on line 1495
PHP Warning:  preg_match() expects parameter 2 to be string, array given in /var/www/CronJobs/aws-sdk-for-php/services/s3.class.php on line 1042
PHP Warning:  preg_match() expects parameter 2 to be string, array given in /var/www/CronJobs/aws-sdk-for-php/services/s3.class.php on line 1043
PHP Notice:  Array to string conversion in /var/www/CronJobs/aws-sdk-for-php/services/s3.class.php on line 548
PHP Fatal error:  Uncaught exception 'S3_Exception' with message 'S3 does not support "Array" as a valid bucket name. Review "Bucket Restrictions and Limitations" in the S3 Developer Guide for more information.' in /var/www/CronJobs/aws-sdk-for-php/services/s3.class.php:548
Stack trace:
0 /var/www/CronJobs/aws-sdk-for-php/services/s3.class.php(1530): AmazonS3->authenticate(Array, Array)
1 [internal function]: AmazonS3->get_object(Array)
2 /var/www/CronJobs/aws-sdk-for-php/sdk.class.php(436): call_user_func_array(Array, Array)
3 /var/www/CronJobs/leefomatic/index.php(70): CFRuntime->__call('getObject', Array)
4 /var/www/CronJobs/leefomatic/index.php(70): AmazonS3->getObject(Array)
5 {main}
thrown in /var/www/CronJobs/aws-sdk-for-php/services/s3.class.php on line 548

在我的脚本中我目前是listObject,copy_object和delete_option就好了。有关为什么在getObject上出现致命错误的任何想法?

感谢。

1 个答案:

答案 0 :(得分:0)

您似乎正在使用带有SDK 2.x代码的SDK 1.x文档。您显示的错误块中的文件名(例如,s3.class.phpsdk.class.php)输出肯定表明您使用的是SDK 1.x代码。您需要安装较新且更受支持的SDK 2.x(here are some instructions),或使用SDK 1.x docs