2

I am trying to upload file in aws-s3 but it shows me some error like enter image description here

NodeCode:

const AWS = require('aws-sdk');
const uploadFile = async (file) => {

    const s3 = new AWS.S3({
        accessKeyId: "<AWSS3_AccessKey>",
        secretAccessKey: "<AWSS3_SecretKey>",
        region: "ap-south-1"
    });

    const params = {
        Bucket: "test123", // pass your bucket name
        Key: file.name, //filename
        Body: file.data, //data
    };
    s3.upload(params, function(s3Err, data) {
        if (s3Err) throw s3Err
        //console.log(`File uploaded successfully at ${data.Location}`)
    });
};

var files = [];
var fileKeys = Object.keys(req.files);

fileKeys.forEach(function(key) {
    var file = req.files[key];
    files.push(file.name);
    uploadFile(file);
});
Juned Ansari
  • 5,035
  • 7
  • 56
  • 89
  • Some time ago I answered a question, demonstrating how to configure an instance of s3 and upload multiple files. See in [SO - Answer](https://stackoverflow.com/questions/52044770/vue-express-uploading-multiple-files-to-amazon-s3/52064836#52064836). – Chance Dec 04 '18 at 11:46
  • @AndersonMendes, above code was working previously but now it is not working. – Juned Ansari Dec 04 '18 at 11:53
  • I understand, I found this [issue](https://github.com/aws/aws-sdk-js/issues/1955) about a possible cause but still no solution. – Chance Dec 04 '18 at 12:01

1 Answers1

2

your aws cli config file in not configured properly the location of config file is

at ~/.aws/config on Linux, macOS, or Unix, or at C:\Users\USERNAME.aws\config on Windows.

you need to setup this file before you use any sdk to call aws services i'm posting a link which will guide you how to setup aws cli in different operating systems

Setup AWS CLI

varnit
  • 1,859
  • 10
  • 21