protected function S3fsCorsPostObjectV4::getPolicyAndSignature in S3 File System CORS Upload 7
1 call to S3fsCorsPostObjectV4::getPolicyAndSignature()
- S3fsCorsPostObjectV4::__construct in ./
s3fs_cors.post_object_v4.class.inc - Constructs the PostObject.
File
- ./
s3fs_cors.post_object_v4.class.inc, line 161 - 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
protected function getPolicyAndSignature(CredentialsInterface $credentials, array $policy) {
$ldt = gmdate('Ymd\\THis\\Z');
// SignatureV4::ISO8601_BASIC
$sdt = substr($ldt, 0, 8);
$policy['conditions'][] = [
'X-Amz-Date' => $ldt,
];
$region = $this->client
->getRegion();
$scope = $this
->createScope($sdt, $region, 's3');
$creds = "{$credentials->getAccessKeyId()}/{$scope}";
$policy['conditions'][] = [
'X-Amz-Credential' => $creds,
];
$policy['conditions'][] = [
'X-Amz-Algorithm' => "AWS4-HMAC-SHA256",
];
$jsonPolicy64 = base64_encode(json_encode($policy));
$key = $this
->getSigningKey($sdt, $region, 's3', $credentials
->getSecretKey());
return [
'X-Amz-Credential' => $creds,
'X-Amz-Algorithm' => "AWS4-HMAC-SHA256",
'X-Amz-Date' => $ldt,
'Policy' => $jsonPolicy64,
'X-Amz-Signature' => bin2hex(hash_hmac('sha256', $jsonPolicy64, $key, true)),
];
}