i have posted tha pdf file to s3 bucket and save the return Location Url path of file in mongodb . so now i want to delete that file data by get mongoid file location url path from mongodb.im not understanding how can i get the aws parms by url path and how can i delete both??. so please help me any one how can i delete this file??
router.delete('/:epdfurl', async function(req, res,next) {
const id = req.params.epdfurl;
const params2 = {
Bucket:bucketName2,
Key:file.booksEpdf[0].originalname,
Body:file.booksEpdf[0].buffer,
acl: 'public-read'
};
s3.deleteObject(params2,(error,data)=>{
if(error){
res.status(500).send({"err":error})
}
const data2=data
console.log(data2)
S3Epdf.remove({ _id: id })
.exec()
.then(result => {
res.send(result)
})
.catch(err => {
res.send(err)
})
})
})
CodePudding user response:
You don't really need to pass the Body in your params2
. Mind you though, the Key should be the full path to the object inside your s3 bucket. eg: path/to/file/my_file.pdf