如何通过使用位置 url 从节点 mongo 删除 s3 对象?
how can i delete the s3 object from Node mongo by use location url?
我已将 pdf 文件发布到 s3 存储桶并将文件的 return 位置 Url 路径保存在 mongodb 中。所以现在我想通过从 mongodb.im 获取 mongoid 文件位置 url 路径来删除该文件数据 不明白如何通过 url 路径获取 aws parms 以及如何删除两者? .所以请帮助我如何删除这个文件?
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)
})
})
})
您真的不需要在 params2
中传递正文。不过请注意,Key 应该是 s3 存储桶中对象的完整路径。例如:path/to/file/my_file.pdf
我已将 pdf 文件发布到 s3 存储桶并将文件的 return 位置 Url 路径保存在 mongodb 中。所以现在我想通过从 mongodb.im 获取 mongoid 文件位置 url 路径来删除该文件数据 不明白如何通过 url 路径获取 aws parms 以及如何删除两者? .所以请帮助我如何删除这个文件?
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)
})
})
})
您真的不需要在 params2
中传递正文。不过请注意,Key 应该是 s3 存储桶中对象的完整路径。例如:path/to/file/my_file.pdf