I can upload it to S3, but the server code I wrote in node.js is gettingObject and I'm going to get the file from S3, but I get a 403 Forbidden error.
What I want to do is to read the photo I uploaded to S3 and display it on the screen, but I can't get the important image from S3.I would like someone to teach me.
I look forward to your kind cooperation.
getImage:function(req,res){
var fileName = req.param('filename');
sails.log.info('fileName='+fileName);
vars3 = new AWS.S3({
region: 'ap-northeast-1'
});
vars3Params = {
bucket —The bucket name obtained from the constant,
Key—fileName
};
s3.getObject(s3Params, function(err,data){
if(err===null){
sails.log.info('ok!');
res.send(data.Body);
} else{
sails.log.error('err='+err.message);
res.status(500).send(err);
}
});
},
The bucket policy for S3 is specified as follows:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowReading",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::xxxxxxxxxxx:user/myusername"
},
"Action"Action"]
"s3:GetObject"
],
"Resource": [
"arn:aws:s3::bucketName",
"arn:aws:s3::bucketName/*"
]
}
]
}
403 Forbidden means you don't have permission, so I think S3 needs to disclose the image file settings.
I think you should check the settings in S3.
https://ja.wikipedia.org/wiki/HTTP_403
© 2024 OneMinuteCode. All rights reserved.