module.exports = function (express, router) {
var _ = require('lodash'),
aws = require('aws-sdk'),
AWSConfig = require('../../config/AWSConfig.json');
router.route('/resource/file/sign')
.post(function (req, res) {
var bucket = "myTestBucket";
aws.config.update({accessKeyId: AWSConfig.AWS_ACCESS_KEY, secretAccessKey: AWSConfig.AWS_SECRET_KEY});
var s3 = new aws.S3();
var options = {
Bucket: bucket,
Key: req.body.name,
Expires: 60,
ContentType: req.body.type,
ACL: 'private'
};
s3.getSignedUrl('putObject', options, function (err, data) {
if (err) {
return res.send('Error with S3')
}
res.json({
signed_request: data,
url: 'https://s3.amazonaws.com/' + bucket + '/' + req.body.name
})
})
});
return router;
};
このリクエストはsigned_request
を返して正しく動作します。Amazon S3署名の動作は禁止されています
しかし、私がURLにアップロードしようとすると、私はリクエストでforbidden
を取得します。
私もCORS
エラーが出る:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 403.
は、これは、あなたのいくつかは正しい方向に私を導くことができるかもしれないことを望んでイムのでamazon s3
を使用しようとしている私の最初の時間です。
UPDATEは、私は今、エラーがなくなってCORSを許可およびCORSヘッダを編集しようとしなかったが、私はまだアップロードすることは禁じられています。ここで
は私の設定です:
バケットポリシー
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AddCannedAcl",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": [
"arn:aws:s3:::learningbank-test/*"
],
"Condition": {
"StringEquals": {
"s3:x-amz-acl": [
"public-read"
]
}
}
}
]
}
権限:(私の最後の)
私の質問を更新しましたか? –