无效的政策文件或要求标头 [英] Invalid policy document or request headers

查看:111
本文介绍了无效的政策文件或要求标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力查看Fine Uploader的相关信息,并获取无效的政策文档或请求标头!"

I have been struggling to see some light on Fine Uploader and getting "Invalid policy document or request headers!"

我的Java脚本

var s3Uploader = new qq.s3.FineUploader({
    debug: true,
    element: document.getElementById('fine-uploader-s3'),
    template: 'qq-template-s3',
    request: {
        endpoint: "http://xx_mybucket_xx.s3.amazonaws.com",
        accessKey: "xx_my_access_public_key_xx"
    },
    signature: {
        endpoint: "http://localhost/app/ci/php-s3-server/endpoint-cors.php"
    },
    uploadSuccess: {
        endpoint: "http://localhost/app/ci/php-s3-server/endpoint-cors.php?success",
        params: {
            isBrowserPreviewCapable: qq.supportedFeatures.imagePreviews
        }
    },

在我的endpoint-cors.php中

in my endpoint-cors.php

$clientPrivateKey = 'xx_my_access_secret_key_xx';
..
$serverPublicKey = 'xx_my_aws_admin_public_key_xx';
$serverPrivateKey = 'xx_my_aws_admin_private_key_xx';
...
$expectedBucketName = 'xx_mybucket_xx';
$expectedHostName = 'http://s3.amazonaws.com'; 

function handleCorsRequest() {  
    header('Access-Control-Allow-Origin: http://localhost');
}

具有密钥xx_my_access_public_key_xx/xx_my_access_secret_key_xx的用户的AWS策略

AWS policy for the user with key xx_my_access_public_key_xx/xx_my_access_secret_key_xx

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::xx_mybucket_xx/*"
        }
    ]
}

AWS CORS

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <ExposeHeader>ETag</ExposeHeader>
        <AllowedHeader>*</AllowedHeader>
        <AllowedHeader>x-amz-acl</AllowedHeader>
        <AllowedHeader>x-amz-meta-qqfilename</AllowedHeader>
        <AllowedHeader>x-amz-date</AllowedHeader>
        <AllowedHeader>authorization</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

请求标头

Request URL:http://localhost/app/ci/php-s3-server/endpoint-cors.php
Request Method:POST
Status Code:200 OK
Remote Address:[::1]:80
Response Headers
view source
Access-Control-Allow-Origin:http://localhost
Connection:Keep-Alive
Content-Length:16
Content-Type:application/json
Date:Mon, 28 Mar 2016 21:10:38 GMT
Keep-Alive:timeout=5, max=98
Server:Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.1
X-Powered-By:PHP/7.0.1
Request Headers
view source
Accept:application/json
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:295
Content-Type:application/json; charset=UTF-8
Cookie:wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_f20b39b0cd3496e33513d2bacf01cb08=testuser%7C1459195033%7CKXV9QrEMyDcLAYJlaGTgICQ74f8iTwm5yUxGjR0SvO0%7C96cdcd43f9a8bb882ca9603a76e08da613398daa202a5b5a1674b5f28ef899a9; PHPSESSID=5bhdaq99o6pa0cagp6d0rsq9s2; _ga=GA1.1.446199661.1458860695
Host:localhost
Origin:http://localhost
Referer:http://localhost/app/ci/s3.fine-uploader/templates/s3test.html
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
Request Payload
view source
{expiration: "2016-03-28T21:15:38.137Z",…}
conditions
:
[{acl: "private"}, {bucket: "xx_mybucket_xx"}, {Content-Type: "image/png"},…]
expiration
:
"2016-03-28T21:15:38.137Z"

响应

{"invalid":true}

推荐答案

服务器的响应表明服务器正在拒绝签名请求.如果您使用的是Fine Uploader GitHub存储库中提供的示例PHP S3签名服务器代码,该请求将由于以下一种或多种原因而被拒绝:

The response from your server indicates that the server is rejecting the signature request. If you are using the example PHP S3 signature server code provided in the Fine Uploader GitHub repo, the request will be rejected for one or more of the following reasons:

    与请求关联的
  • 桶与您在PHP文件中为$expectedBucketName变量设置的值不匹配.如果您提供的存储桶名称不正确,可能会发生这种情况.检查并确保您提供的存储桶名称正确.

  • Bucket associated with the request does not match the value you have set for the $expectedBucketName variable in your PHP file. This could happen if the bucket name you have provided in not correct. Check and be sure the bucket name you have provided is accurate.

文件的大小大于为$expectedMaxSize指定的值.如果不想验证大小,则应将其设置为null;如果 do 要将文件限制为特定大小,则应将其设置为特定的字节数.

Size of the file is greater than the value you have specified for $expectedMaxSize. You should set this to null if you don't want to validate size, or a specific number in bytes if you do want to restrict files to a certain size.

此外,似乎没有任何理由使您可以使用endpoint-cors.php.根据您发布的JS,对签名服务器的所有请求均来自同一来源.您应该使用endpoint.php.

Also, there doesn't appear to be any reason for you to use endpoint-cors.php. Based on the JS you have posted, all requests to your signature server are same-origin. You should be using endpoint.php.

这篇关于无效的政策文件或要求标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆