尝试使用AWS SDK for PHP生成预签名查询字符串以POST到S3存储桶。得到以下错误:
我们计算的请求签名与您提供的签名不符。
这是生成网址的php文件,改编自here。
<?php
require('./aws/aws-autoloader.php');
$client = new \Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => [
'key' => '[KEY]',
'secret' => '[SECRET]',
],
]);
$bucket = '[mybucket]';
// Set some defaults for form input fields
$formInputs = ['acl' => 'public-read'];
// Construct an array of conditions for policy
$options = [
['acl' => 'bucket-owner-full-control'],
['bucket' => $bucket],
];
// Optional: configure expiration time string
$expires = '+2 hours';
$postObject = new \Aws\S3\PostObjectV4(
$client,
$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();
echo "https://[mybucket].s3.amazonaws.com/?".http_build_query($formInputs)."&X-Amz-Expires=7200&X-Amz-SignedHeaders=host";
?>
curl命令:
curl --request POST --upload-file "file.gif" -k [query string here]