Ejemplo n.º 1
0
 /**
  * Constructs the PostObject.
  *
  * @param S3ClientInterface $client     Client used with the POST object
  * @param string            $bucket     Bucket to use
  * @param array             $formInputs Associative array of form input
  *                                      fields.
  * @param string|array      $jsonPolicy JSON encoded POST policy document.
  *                                      The policy will be base64 encoded
  *                                      and applied to the form on your
  *                                      behalf.
  */
 public function __construct(S3ClientInterface $client, $bucket, array $formInputs, $jsonPolicy)
 {
     $this->client = $client;
     $this->bucket = $bucket;
     if (is_array($jsonPolicy)) {
         $jsonPolicy = json_encode($jsonPolicy);
     }
     $this->jsonPolicy = $jsonPolicy;
     $this->formAttributes = ['action' => $this->generateUri(), 'method' => 'POST', 'enctype' => 'multipart/form-data'];
     $this->formInputs = $formInputs + ['key' => '${filename}'];
     $credentials = $client->getCredentials()->wait();
     $this->formInputs += $this->getPolicyAndSignature($credentials);
 }
 /**
  * Creates an UploadState object for a multipart upload by querying the
  * service for the specified upload's information.
  *
  * @param S3ClientInterface $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(S3ClientInterface $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;
 }