|
#!/usr/bin/php |
|
<?php |
|
|
|
require_once "./vendor/autoload.php"; |
|
|
|
$bucket = 'post-tests'; |
|
$endpoint = 'sos-ch-dk-2.exo.io'; |
|
|
|
$s3 = new Aws\S3\S3Client([ |
|
'endpoint' => sprintf("https://%s", $endpoint), |
|
'version' => 'latest', |
|
'region' => 'ch-dk-2', |
|
'credentials' => [ |
|
'key' => 'YOUR_KEY', |
|
'secret' => 'YOUR_SECRET' |
|
] |
|
]); |
|
|
|
|
|
// Set some defaults for form input fields |
|
$formInputs = [ |
|
'acl' => 'public-read-write', |
|
]; |
|
|
|
// Construct an array of conditions for policy |
|
$options = [ |
|
['starts-with', '$key' ,''], |
|
['acl' => 'public-read-write'], |
|
['bucket' => $bucket], |
|
["starts-with", '$Content-Type', ''], |
|
]; |
|
|
|
// Optional: configure expiration time string |
|
$expires = '+2 hours'; |
|
|
|
$postObject = new \Aws\S3\PostObjectV4( |
|
$s3, |
|
$bucket, |
|
$formInputs, |
|
$options, |
|
$expires |
|
); |
|
|
|
// Get attributes to set on an HTML form, e.g., action, method, enctype |
|
$formAttributes = $postObject->getFormAttributes(); |
|
|
|
// Get form input fields. This will include anything set as a form input in |
|
// the constructor, the provided JSON policy, your AWS Access Key ID, and an |
|
// auth signature. |
|
$formInputs = $postObject->getFormInputs(); |
|
|
|
$curlParams = array(); |
|
|
|
foreach($formInputs as $key => $value) { |
|
array_push($curlParams, sprintf('--form %s=%s', $key, $value)); |
|
} |
|
/* array_push($curlParams, '--form "file=@images.png"'); */ |
|
array_push($curlParams, sprintf("https://%s/%s", $endpoint, $bucket)); |
|
|
|
|
|
echo implode(' ', $curlParams); |
|
?> |