Reputation: 15
I have front-end react, and back-end node. I am trying to send a signed AWS url from server to client side. The weird thing is, the server shows proper url address; it prints:
https://*****.s3.amazonaws.com/abd160218_000.jpg?AWSAccessKeyId=XXXX&Content-Type=image%2Fjpeg&Expires=1487035862&Signature=g6ti%2FN27Uw9O7ihThSr1G79nAmc%3D&x-amz-acl=public-read
and sends back the url with:
res.send({signedUrl: data});
However, after immediately receiving the url on client-side, the url shows:
https://******.dynamodb.us-east-1.amazonaws.com/abd1601…487037678&Signature=wC6iKrTeaOYHyNW5QPoTE%2FzAZ10%3D&x-amz-acl=public-read
Which is really confusing me. I am fetching the url from server with axios:
axios.get('/blogs/aws/getSignedAWSUrl', {
params: {
filename: el.file.name,
filetype: el.file.type
}
})
.then(function (result) {
//AWS s3 signed url returned from server.
var signedUrl = result.data.signedUrl;
console.log("Signed URl:", signedUrl);
var options = {
headers: {
'Content-Type': el.file.type,
}
};
axios.put(signedUrl, el.file, options);
})
How can this actually happen?? I would appreciate any tips and ideas.
**Update- node.js code
module.exports.getSignedAWSUrl = function(req, res){
var {filename, filetype} = req.query;
AWS.config.update({
accessKeyId: aws.ACCESS_KEY,
secretAccessKey: aws.SECRET_KEY,
});
var bucket = new AWS.S3();
var params = {
Bucket: 'mybucket',
Key: filename,
Expires: 60,
ContentType: filetype,
ACL: 'public-read',
};
bucket.getSignedUrl('putObject', params, function(err, data){
if(err){
console.log(err);
return err;
}
else{
console.log("Aws Signed URL:", data);
res.send({signedUrl: data});
}
});
}
Upvotes: 0
Views: 237
Reputation: 15
I finally figured out...
In my index page, I would configure my AWS to fetch data from dynamoDB. Then when I try to post something new, the AWS config wouldn't have the proper endpoint. For example, if you read my AWS configure to get the signed aws url, I don't update the endpoint; all I do is insert access and secret key.
I've updated it so that @ getSignedUrl, the AWS configure would be
AWS.configure.update({
endpoint: "s3.amazonaws.com",
accessKeyID: aws.ACCESS_KEY,
secretAccessKey: aws.SECRET_KEY
});
Sorry to the people who tried to help. The context was impossible for you guys to help with my provided info, and I didn't think the index page would be causing the problem. I appreciate the advices.
Thanks.
Upvotes: 1