【发布时间】: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