Esempio n. 1
0
 protected function loadStateByUploadId(array $params = [])
 {
     $state = new UploadState($params);
     $partSize = null;
     foreach ($this->client->getIterator('ListParts', $params) as $part) {
         if (!$partSize) {
             $partSize = $part['Size'];
         }
         $state->markPartAsUploaded($part['PartNumber'], ['PartNumber' => $part['PartNumber'], 'ETag' => $part['ETag']]);
     }
     $state->setPartSize($partSize);
     $state->setStatus($state::INITIATED);
     return $state;
 }
 /**
  * Creates an UploadState object for a multipart upload by querying the
  * service for the specified upload's information.
  *
  * @param S3Client $client   S3Client used for the upload.
  * @param string   $bucket   Bucket for the multipart upload.
  * @param string   $key      Object key for the multipart upload.
  * @param string   $uploadId Upload ID for the multipart upload.
  *
  * @return UploadState
  */
 public static function getStateFromService(S3Client $client, $bucket, $key, $uploadId)
 {
     $state = new UploadState(['Bucket' => $bucket, 'Key' => $key, 'UploadId' => $uploadId]);
     foreach ($client->getPaginator('ListParts', $state->getId()) as $result) {
         // Get the part size from the first part in the first result.
         if (!$state->getPartSize()) {
             $state->setPartSize($result->search('Parts[0].Size'));
         }
         // Mark all the parts returned by ListParts as uploaded.
         foreach ($result['Parts'] as $part) {
             $state->markPartAsUploaded($part['PartNumber'], ['PartNumber' => $part['PartNumber'], 'ETag' => $part['ETag']]);
         }
     }
     $state->setStatus(UploadState::INITIATED);
     return $state;
 }
 /**
  * Creates an UploadState object for a multipart upload by querying the
  * service for the specified upload's information.
  *
  * @param GlacierClient $client    GlacierClient object to use.
  * @param string        $vaultName Vault name for the multipart upload.
  * @param string        $uploadId  Upload ID for the multipart upload.
  * @param string        $accountId Account ID for the multipart upload.
  *
  * @return UploadState
  */
 public static function getStateFromService(GlacierClient $client, $vaultName, $uploadId, $accountId = '-')
 {
     $state = new UploadState(['accountId' => $accountId, 'vaultName' => $vaultName, 'uploadId' => $uploadId]);
     foreach ($client->getPaginator('ListParts', $state->getId()) as $result) {
         // Get the part size from the first part in the first result.
         if (!$state->getPartSize()) {
             $state->setPartSize($result['PartSizeInBytes']);
         }
         // Mark all the parts returned by ListParts as uploaded.
         foreach ($result['Parts'] as $part) {
             list($rangeIndex, $rangeSize) = self::parseRange($part['RangeInBytes'], $state->getPartSize());
             $state->markPartAsUploaded($rangeIndex, ['size' => $rangeSize, 'checksum' => $part['SHA256TreeHash']]);
         }
     }
     $state->setStatus(UploadState::INITIATED);
     return $state;
 }
 /**
  * Based on the config and service-specific workflow info, creates a
  * `Promise` for an `UploadState` object.
  *
  * @return PromiseInterface A `Promise` that resolves to an `UploadState`.
  */
 private function determineState()
 {
     // If the state was provided via config, then just use it.
     if ($this->config['state'] instanceof UploadState) {
         return $this->config['state'];
     }
     // Otherwise, construct a new state from the provided identifiers.
     $required = $this->info['id'];
     $id = [$required['upload_id'] => null];
     unset($required['upload_id']);
     foreach ($required as $key => $param) {
         if (!$this->config[$key]) {
             throw new IAE('You must provide a value for "' . $key . '" in ' . 'your config for the MultipartUploader for ' . $this->client->getApi()->getServiceFullName() . '.');
         }
         $id[$param] = $this->config[$key];
     }
     $state = new UploadState($id);
     $state->setPartSize($this->determinePartSize());
     return $state;
 }
Esempio n. 5
0
 protected function loadStateByUploadId(array $params = [])
 {
     $state = new UploadState($params);
     // Get all of the parts and archive information
     $partSize = null;
     $results = $this->client->getPaginator('ListParts', $params);
     foreach ($results as $result) {
         if (!$partSize) {
             $partSize = $result['PartSizeInBytes'];
         }
         foreach ($result['Parts'] as $part) {
             $rangeData = $this->parseRange($part['RangeInBytes'], $partSize);
             $state->markPartAsUploaded($rangeData['PartNumber'], ['size' => $rangeData['Size'], 'checksum' => $part['SHA256TreeHash']]);
         }
     }
     $state->setPartSize('partSize', $partSize);
     $state->setStatus($state::INITIATED);
     return $state;
 }