[英]Cannot delete image from aws s3 bucket
我想通过 express.js 删除存储在 AWS S3 存储桶中的一张图片,但我遇到了一个问题。 下面是我写的代码
const imageurl=req.user.imageurl.split("/");
// console.log(imageurl);
const imgfile=imageurl[imageurl.length-1]
// imgfile[0] = "4a05123a-506f-4c22-896a-8b6595b95d66Cover.jpg"
console.log(imgfile);
const params ={
Bucket: process.env.aws_bucket_name,
Key: imgfile
}
s3.deleteObject(params, (error, data) => {
if (error) {
res.status(500).send(error);
}
console.log(data);
res.status(200).send("File has been deleted successfully");
});
在这里,一切正常,但是当我运行这段代码然后查看我的 S3 存储桶时,图像仍然存在。
我发现了导致错误的问题。 我的“imgfile”是一个包含第 0 个索引处的字符串的数组。 我将它作为 imgfile 而不是 imgfile[0] 传递。
很抱歉给您带来麻烦。 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.