I generate Pre-Signed URL on the server side and loading fileon the client side.
For some reason, I get an error 403 forbidden SignatureDoesNotMatchfrom AWS, but I do not see where the error is.
Using postmanto request URL, what I get as response:
https://s3-us-west-2.amazonaws.com/my_bucket/uploads/%20VID_20160916_061949.mp4?AWSAccessKeyId=AKIAJV3UP7LBEKPYMLGA&Expires=1474005709&Signature=7KYWah4K%2FEkpdYQR%2FqYDrvCDPgQ%3D
Here below I insert my code:
Angularjs
$http.post(CONFIG.API_URL + '/endpoint1', { filename: videoData[0].name })
.success(function (resp) {
$http.put(resp, videoData[0], { headers: {'Content-Type': videoData[0].type} })
.success(function (resp) {
callback(null, 'Upload Done!');
})
.error(function (resp) {
callback("An Error Occurred Attaching Your File");
});
})
.error(function (resp) {
callback("An Error Occurred Attaching Your File");
});
NodeJS
getSignedUrl: function (filename, callback) {
if (filename) {
AWS.config.update({
accessKeyId: 'my_access_key',
secretAccessKey: 'my_secret_key',
region: 'us-west-2'
});
var s3 = new AWS.S3();
s3.getSignedUrl('putObject', {Bucket: 'my_bucket', Key: 'uploads/' + filename}, function (err, url) {
if (err) {
callback(err);
} else {
callback(url);
}
});
} else {
callback('Error');
}
}
Bucket Policy
{
"Version": "2012-10-17",
"Id": "Policy1474002303781",
"Statement": [
{
"Sid": "Stmt1473001308637",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::my_user:root"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::my_bucket/uploads"
}
]
}
CORS
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>600</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Can someone help me?
Thanks, advice!