You are here

public function S3fsCorsPostObjectV4::__construct in S3 File System CORS Upload 7

Constructs the PostObject.

The options array accepts the following keys: @link http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html

Parameters

S3ClientInterface $client Client used with the POST object:

string $bucket Bucket to use:

array $formInputs Associative array of form input: fields.

array $options Policy condition options:

mixed $expiration Upload expiration time value. By: default: 1 hour valid period.

File

./s3fs_cors.post_object_v4.class.inc, line 44
The code of classes was taken from the AWS SDK v3.180.3 and a bit modified. Next classes are used here:

Class

S3fsCorsPostObjectV4
Encapsulates the logic for getting the data for an S3 object POST upload form

Code

public function __construct(S3ClientInterface $client, $bucket, array $formInputs, array $options = [], $expiration = '+1 hours') {
  $this->client = $client;
  $this->bucket = $bucket;

  // setup form attributes
  $this->formAttributes = [
    'action' => $this
      ->generateUri(),
    'method' => 'POST',
    'enctype' => 'multipart/form-data',
  ];
  $credentials = $this->client
    ->getCredentials();
  if ($securityToken = $credentials
    ->getSecurityToken()) {
    $options[] = [
      'x-amz-security-token' => $securityToken,
    ];
    $formInputs['X-Amz-Security-Token'] = $securityToken;
  }

  // setup basic policy
  $policy = [
    'expiration' => gmdate('Y-m-d\\TH:i:s\\Z', strtotime($expiration)),
    'conditions' => $options,
  ];

  // setup basic formInputs
  $this->formInputs = $formInputs + [
    'key' => '${filename}',
  ];

  // finalize policy and signature
  $this->formInputs += $this
    ->getPolicyAndSignature($credentials, $policy);
}