lib/awsFileExists.js ->
const aws = require("aws-sdk");
const { config } = require("../../config");
// 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.getFileFromS3 = async (fullPath) => {
var params = {
Bucket: config.aws.bucket,
Key: fullPath,
};
try {
await s3.headObject(params).promise();
return true;
} catch (error) {
return false;
}
};
router->
const awsFileExists = require("../../lib/awsFileExists");
router.route("/").get(async (req, res) => {
//'thumbnail' 이건 formdata의 칼럼명
try {
let result = await awsFileExists.getFileFromS3(
"image/photo_2020-09-09_13-29-16.jg"
);
res.json({ result });
} catch (e) {
console.log(e);
res.status(400).json({ code: 0, reason: "bad request" });
}
});
댓글
댓글 쓰기