Reputation: 11
I am trying to upload my data using postman. I have integrated amazon s3 bucket with it. But after I try to POST particular data, the postman throws an error: "Access Denied". Here is my code:
exports.vehicles_create_vehicle = (req, res, next) => {
const vehicle = new Vehicle({
_id: new mongoose.Types.ObjectId(),
name: req.body.name,
category: req.body.category,
price: req.body.price,
vehicleImage: req.files[0].location,
baseFare: req.body.baseFare,
});
vehicle
.save()
.then(result => {
console.log(result);
res.status(201).json({
message: "Created product successfully",
createdProduct: {
name: result.name,
price: result.price,
category: result.category,
_id: result._id,
request: {
type: "GET",
url: "http://localhost:3000/vehicles/" + result._id
}
}
});
})
.catch(err => {
console.log(err);
res.status(500).json({
error: err
});
});
};
And here is my bucket coding:
var aws = require('aws-sdk')
var multerS3 = require('multer-s3')
aws.config.update({
signatureVersion: 'v4',
secretAccessKey:'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
accessKeyId: 'xxxxxxxxxxxxxxxxx',
region: 'us-east-2'
})
var s3 = new aws.S3()
var upload = multer({
storage: multerS3({
s3: s3,
bucket: 'one-way-travel',
key: function (req, file, cb) {
cb(null, Date.now()+file.originalname.replace(/\s+/g, '-'));
}
})
})
I could not understand the reason for the error. Please help to figure it out.
Upvotes: 0
Views: 436
Reputation: 638
To troubleshoot HTTP 403: Access Denied errors from Amazon S3, check the following:
Source: Amazon Knowledge Center.
Upvotes: 2