I'm using aws s3 to upload images but I keep getting the error: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1. There are several posts which talk about the same error but I couldn't solve it. I'm using a .env enviroment file with the required private keys. Thanks in advance.
Here is the code:
const aws = require('aws-sdk');
const multer = require('multer');
const multerS3 = require('multer-s3');
const dotenv = require('dotenv');
dotenv.config();
const s3 = new aws.S3({});
aws.config.update({
secretAccesKey: process.env.S3_ACCES_KEY,
accessKeyId: process.env.S3_ACCES_KEY_SECRET,
region: "eu-west-3",
});
const fileFilter = (req, file, cb)=>{
if(file.mimetype === "image/jpeg" || file.mimetype === "image/png"){
cb(null, true);
}else{
cb(new Error("Invalid file type, file must be JPG or PNG."), false);
}
}
const upload = multer({
fileFilter,
storage: multerS3({
acl: "public-read",
s3: s3,
bucket: "projectoene",
acl: 'public-read',
metadata: function(req,file, cb){
cb(null, {fieldName: "Test"});
},
key: function(req,file,cb){
cb(null, Date.now().toString());
},
}),
});
module.exports = upload;
ACCESinstead ofACCESS? - jordanm