最新バージョンの SDK を使用している場合は、代わりにこの方法でコマンドを作成してみてください。ドキュメントから直接取得; それはうまくいくはずです。これは「チェーン」方式と呼ばれます。
$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()
ます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
コマンド結果の配列である必要があります。