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