AWS S3 Nodejs 파일삭제
Lib->deleteS3.js
const { config } = require("../../config");
// AWS
const aws = require("aws-sdk");
// aws S3
const s3 = new aws.S3();
aws.config.update({
secretAccessKey: config.aws.secret_access_key, // Not working key, Your SECRET ACCESS KEY from AWS should go here, never share it!!!
accessKeyId: config.aws.access_key_id, // Not working key, Your ACCESS KEY ID from AWS should go here, never share it!!!
region: config.aws.region, // region of your bucket
});
exports.delete = (fullPath) => {
return s3.deleteObject(
{
Bucket: config.aws.bucket, // 사용자 버켓 이름
Key: fullPath, // 버켓 내 경로
},
(err, data) => {
if (err) {
throw err;
}
console.log("s3 deleteObject ", data);
}
);
};
router->
router.route("/").get(async (req, res) => {
//'thumbnail' 이건 formdata의 칼럼명
try {
await awsDelete.delete("image/Untitled.png");
res.json({ result: "done" });
} catch (e) {
console.log(e);
res.status(400).json({ code: 0, reason: "bad request" });
}
});
댓글
댓글 쓰기