2015-07-10 15 views
5

Ich folgte diese Codes zu Charge PutObject in S3. Ich benutze das neueste PHP SDK (3.x). Aber ich bin immer:S3 Batch/Parallel Upload Fehler mit PHP SDK

Argument 1 zu Aws geben \ AwsClient :: execute() muss Schnittstelle Aws \ CommandInterface implementieren, Array

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

Antwort

4

Wenn Sie eine moderne Version verwenden von das SDK, versuchen Sie stattdessen, den Befehl auf diese Weise zu erstellen. Genommen direkt von der docs; es sollte funktionieren. Dies wird als "Verkettung" bezeichnet.

$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. 
} 

Stellen Sie sicher, dass Sie die neueste Version des SDK verwenden.

bearbeiten

Es scheint, dass das API des SDK deutlich in Version 3.x geändert hat Das obige Beispiel sollte in Version 2.x des AWS SDK ordnungsgemäß funktionieren. Für 3.x, müssen Sie CommandPool() s und promise() verwenden:

$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. 
} 

Dann sollte $result ein Array von Befehlsergebnisse sein.

+0

Ist das nicht das gleiche wie ich es codiert habe? Der Fehler ist fehlgeschlagen bei $ s3-> execute ($ commands); – twb

+0

Der Unterschied ist die '-> set()' Verkettung und nicht die 'array()' Parameter. Welche Version verwendest du? – Will

+0

Hat nicht funktioniert. Verwenden von ## 3.0.4 - 2015-06-11. Aufruf zu undefinierter Methode Aws \ Command :: set() – twb