【问题标题】:Receiving "Invalid policy document or request headers!"收到“无效的策略文档或请求标头!”
【发布时间】:2016-03-29 04:46:14
【问题描述】:

我正在尝试按照您的文档和源文件中提供的示例将文件上传到 S3。不幸的是,我在尝试上传时收到以下错误:

[Fine Uploader 5.3.2] 无效的策略文档或请求标头!

[Fine Uploader 5.3.2] 策略签名失败。无效的政策文件 或请求标头!

我在这里发现了一些类似错误的帖子,但这些解决方案对我没有帮助。

这是我的 jQuery:

<script>
    $('#fine-uploader').fineUploaderS3({
        request: {
            endpoint: "http://mybucket.s3.amazonaws.com",
            accessKey: "changeme"
        },
        signature: {
        endpoint: "endpoint.php"
        },
        uploadSuccess: {
            endpoint: "success.html"
        },        
        template: 'qq-template'
    });
</script>

(请注意,为了安全起见,我更改了密钥/存储桶名称。)

我使用了您的 endpoint-cors.php 作为模型,并包含了我在此处修改的部分:

require 'assets/aws/aws-autoloader.php';
use Aws\S3\S3Client;

// These assume you have the associated AWS keys stored in
// the associated system environment variables
$clientPrivateKey = $_ENV['changeme'];
// These two keys are only needed if the delete file feature is enabled
// or if you are, for example, confirming the file size in a successEndpoint
// handler via S3's SDK, as we are doing in this example.
$serverPublicKey = $_ENV['AWS_SERVER_PUBLIC_KEY'];
$serverPrivateKey = $_ENV['AWS_SERVER_PRIVATE_KEY'];

// The following variables are used when validating the policy document
// sent by the uploader. 
$expectedBucketName = $_ENV['mybucket'];
// $expectedMaxSize is the value you set the sizeLimit property of the 
// validation option. We assume it is `null` here. If you are performing
// validation, then change this to match the integer value you specified
// otherwise your policy document will be invalid.
// http://docs.fineuploader.com/branch/develop/api/options.html#validation-option
$expectedMaxSize = (isset($_ENV['S3_MAX_FILE_SIZE']) ? $_ENV['S3_MAX_FILE_SIZE'] : null);

我也改了这个:

// Only needed in cross-origin setups
function handleCorsRequest() {
// If you are relying on CORS, you will need to adjust the allowed domain here.
header('Access-Control-Allow-Origin: http://test.mydomain.com');
}

POST 似乎有效:

发布http://test.mydomain.com/somepath/endpoint.php 200 OK 318毫秒

...但这就是成功的终点。

我认为部分问题在于我不确定要为“clientPrivateKey”输入什么内容。那是我用 IAM 设置的“秘密访问密钥”吗?

而且我绝对不清楚从哪里获得 serverPublicKey 和 serverPrivateKey。我在哪里生成 S3 上的密钥对?我梳理了文档,也许我错过了。

提前感谢您的帮助!

【问题讨论】:

    标签: amazon-s3 fine-uploader amazon-iam


    【解决方案1】:

    首先,您在非CORS 环境中使用endpoint-cors.php。根据您的签名端点的 URL,浏览器和您的端点之间的通信似乎是同源的。切换到 endpoint.php 示例。

    关于您关于密钥的问题,您应该创建两个不同的 IAM 用户:一个用于客户端操作(受到严格限制),另一个用于服务器端操作(管理员用户)。对于每个用户,您将拥有一个访问密钥(公共)和一个秘密密钥(私有)。您始终为 Fine Uploader 提供您的客户端公钥,并使用您的客户端私钥在服务器端签署请求。要执行其他更受限制的操作(例如删除文件),您应该使用您的服务器用户密钥。

    【讨论】:

    • 感谢您的回复。我按照您的说明切换到 endpoint.php 示例,像以前一样填写环境变量......但我仍然收到相同的错误:“无效的策略文档或请求标头!”和“策略签名失败。策略文档或请求标头无效!”我可以提供哪些额外信息?
    • 几天前(11 月 6 日),我购买了此产品的许可证以及技术支持票以帮助解决此问题。我没有听到任何回音,甚至没有确认机票。我需要做些什么才能让我的机票引起注意?非常感谢。
    • @mrbranden 您的邮件被我们的垃圾邮件过滤器捕获。现在回应它。
    猜你喜欢
    • 1970-01-01
    • 2013-08-23
    • 2020-10-14
    • 2019-02-12
    • 1970-01-01
    • 2016-03-26
    • 1970-01-01
    • 2013-08-22
    相关资源
    最近更新 更多