Amazon s3 PHP SDK出现S3批处理/并行上载错误
我按照这些代码将对象批处理到S3中。我正在使用最新的PHPSDK(3.x)。但我得到了: 传递给Aws\AwsClient::execute()的参数1必须实现Aws\CommandInterface接口,给定数组Amazon s3 PHP SDK出现S3批处理/并行上载错误,amazon-s3,aws-sdk,aws-php-sdk,Amazon S3,Aws Sdk,Aws Php Sdk,我按照这些代码将对象批处理到S3中。我正在使用最新的PHPSDK(3.x)。但我得到了: 传递给Aws\AwsClient::execute()的参数1必须实现Aws\CommandInterface接口,给定数组 如果您使用的是SDK的现代版本,请尝试以这种方式构建命令。直接从照片上取下;它应该会起作用。这称为“链接”方法 确保您使用的是最新版本的SDK 编辑 SDK的API在3.x版中似乎发生了重大变化。上述示例应在AWS SDK的2.x版中正常工作。对于3.x,您需要使用CommandPo
如果您使用的是SDK的现代版本,请尝试以这种方式构建命令。直接从照片上取下;它应该会起作用。这称为“链接”方法 确保您使用的是最新版本的SDK 编辑 SDK的API在3.x版中似乎发生了重大变化。上述示例应在AWS SDK的2.x版中正常工作。对于3.x,您需要使用
CommandPool()
s和promise()
:
那么,
$result
应该是一个命令结果数组。这与我编写的代码不一样吗?错误在$s3->execute($commands)处失败;不同之处在于参数的->set()
链接,而不是数组()。你用的是什么版本?没用。使用##3.0.4-2015-06-11。调用未定义的方法Aws\Command::set(),我刚刚为Aws SDK 3.x添加了一个新示例。他们已经做出了重大的改变。让我知道这是否适用于您。该示例在->设置('Bucket',$Bucket')时仍将失败??
$commands = array();
$commands[] = $s3->getCommand('PutObject', array(
'Bucket' => $bucket,
'Key' => 'images/1.jpg',
'Body' => base64_decode( 'xxx' ),
'ACL' => 'public-read',
'ContentType' => 'image/jpeg'
));
$commands[] = $s3->getCommand('PutObject', array(
'Bucket' => $bucket,
'Key' => 'images/2.jpg',
'Body' => base64_decode( 'xxx' ),
'ACL' => 'public-read',
'ContentType' => 'image/jpeg'
));
// Execute the commands in parallel
$s3->execute($commands);
$commands = array();
$commands[] = $s3->getCommand('PutObject')
->set('Bucket', $bucket)
->set('Key', 'images/1.jpg')
->set('Body', base64_decode('xxx'))
->set('ACL', 'public-read')
->set('ContentType', 'image/jpeg');
$commands[] = $s3->getCommand('PutObject')
->set('Bucket', $bucket)
->set('Key', 'images/2.jpg')
->set('Body', base64_decode('xxx'))
->set('ACL', 'public-read')
->set('ContentType', 'image/jpeg');
// Execute the commands in parallel
$s3->execute($commands);
// Loop over the commands, which have now all been executed
foreach ($commands as $command)
{
$result = $command->getResult();
// Use the result.
}
$commands = array();
$commands[] = $s3->getCommand('PutObject', array(
'Bucket' => $bucket,
'Key' => 'images/1.jpg',
'Body' => base64_decode ( 'xxx' ),
'ACL' => 'public-read',
'ContentType' => 'image/jpeg'
));
$commands[] = $s3->getCommand('PutObject', array(
'Bucket' => $bucket,
'Key' => 'images/2.jpg',
'Body' => base64_decode ( 'xxx' ),
'ACL' => 'public-read',
'ContentType' => 'image/jpeg'
));
$pool = new CommandPool($s3, $commands);
// Initiate the pool transfers
$promise = $pool->promise();
// Force the pool to complete synchronously
try {
$result = $promise->wait();
} catch (AwsException $e) {
// handle the error.
}