Missing credentials in config while uploading image to AWS S3

Viewed 18

Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1 Everytime I try to post images though postman toaws s3 I am getting this error.

require("./config/database").connect();
const express = require("express");
const jwt = require("jsonwebtoken");
const fileUpload = require("express-fileupload");
var bcrypt = require("bcryptjs");
const app = express();
app.use(fileUpload());
var AWS = require("aws-sdk");
app.post("/images", async (req, res) => {
  AWS.config.update({
    accessKeyId:process.env.AWS_ACCESS_KEY ,
    secretAccesskey: process.env.AWS_SECRET_KEY,
    region: process.env.AWS_BUCKET_REGION,
  });
  const s3 = new AWS.S3();
  const fileContent = Buffer.from(req.files.data.data, "binary");
  const params = {
    Bucket:"newawspracticeimage",
    Key: req.files.data.name,
    Body: fileContent,
  };
  s3.upload(params, (err, data) => {
    if (err) {
      throw err;
    }
    res.send({
      response_code: 200,
      response_message: "Success",
      response_data: data,
    });
  });
});```
1 Answers
Related