/**
  * Perform the configured copy asynchronously. Returns a promise that is
  * fulfilled with the result of the CompleteMultipartUpload or CopyObject
  * operation or rejected with an exception.
  *
  * @return \GuzzleHttp\Promise\Promise
  */
 public function promise()
 {
     return \GuzzleHttp\Promise\coroutine(function () {
         $objectStats = (yield $this->client->executeAsync($this->client->getCommand('HeadObject', $this->source)));
         if ($objectStats['ContentLength'] > $this->options['mup_threshold']) {
             $mup = new MultipartCopy($this->client, $this->getSourcePath(), ['source_metadata' => $objectStats, 'acl' => $this->acl] + $this->destination + $this->options);
             (yield $mup->promise());
         } else {
             $defaults = ['ACL' => $this->acl, 'MetadataDirective' => 'COPY', 'CopySource' => $this->getSourcePath()];
             $params = array_diff_key($this->options, self::$defaults) + $this->destination + $defaults + $this->options['params'];
             (yield $this->client->executeAsync($this->client->getCommand('CopyObject', $params)));
         }
     });
 }
Esempio n. 2
0
 private function doCopyAsync(array $source, array $destination, $acl, array $options)
 {
     return function () use($source, $destination, $acl, $options) {
         $sourcePath = '/' . $source['Bucket'] . '/' . rawurlencode($source['Key']);
         if ($options['version_id']) {
             $sourcePath .= "?versionId={$options['version_id']}";
             $source['VersionId'] = $options['version_id'];
         }
         $objectStats = (yield $this->headObjectAsync($source));
         if ($objectStats['ContentLength'] > $options['mup_threshold']) {
             $mup = new MultipartCopy($this, $sourcePath, $destination + ['source_metadata' => $objectStats, 'acl' => $acl] + $options);
             (yield $mup->promise());
         } else {
             (yield $this->copyObjectAsync($options + $destination + ['ACL' => $acl, 'MetadataDirective' => 'COPY', 'CopySource' => $sourcePath] + $options['params']));
         }
     };
 }