SDK,请尝试以这种方式构建命令,而不是。直接从docs;它应该工作。这被称为“链接”方法。
$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.
}
请确保您使用的是最新版本的SDK。
编辑
看来,SDK的API已经在版本3.x显著变化上述示例应该在AWS SDK的2.x版本中正常工作。对于3.x中,你需要使用CommandPool()
S和promise()
:
$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.
}
然后,$result
应该是命令结果的数组。
这与我编码的不一样吗?该错误在$ s3-> execute($ commands)失败; – twb
区别在于' - > set()'链接而不是参数的'array()'。你使用什么版本? – Will
没有工作。使用## 3.0.4 - 2015-06-11。调用未定义的方法Aws \ Command :: set() – twb