7

これらのコードに従って、PutObjectS3 にバッチ処理しました。最新の PHP SDK (3.x) を使用しています。しかし、私は得ています:

Aws\AwsClient::execute() に渡される引数 1 は、インターフェース Aws\CommandInterface を実装する必要があります。

$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);
4

1 に答える 1

6

最新バージョンの 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コマンド結果の配列である必要があります。

于 2015-07-10T07:24:17.180 に答える