0
votes

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;
2
Could the issue be that you typoed ACCES instead of ACCESS? - jordanm
No, I changed it and reload it but didn't worko - M4RCKIT0S

2 Answers

0
votes

I had to change my bucket policy cors and some permissions. Worked well after that

0
votes

I got the same error message when uploading the image to s3 from the backend. I put the actual aws values without using env, so it worked well.