AWS S3 Presigned POST to URL query string for curl

为君一笑 提交于 2019-12-25 16:55:55

问题


trying to generate a pre-signed query string to POST to an S3 bucket using the AWS SDK for PHP. Getting the following error:

The request signature we calculated does not match the signature you provided.

Here's the php file to generate the URL, adapted from 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";
 ?>

And the curl command:

curl --request POST --upload-file "file.gif" -k [query string here]

来源:https://stackoverflow.com/questions/43991783/aws-s3-presigned-post-to-url-query-string-for-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!