To create folder or key on s3 using AWS SDK for Node.js, we call the upload
method.
For instance, we write
const AWS = require("aws-sdk");
AWS.config.region = "us-east-1";
const s3Client = new AWS.S3();
const params = {
Bucket: "your_bucket_goes_here",
Key: "folderInBucket/",
ACL: "public-read",
Body: "body does not matter",
};
s3Client.upload(params, (err, data) => {
if (err) {
console.log("Error creating the folder: ", err);
} else {
console.log("Successfully created a folder on S3");
}
});
to call upload
with the params
object that has the Bucket
and Key
of the file.
And Body
has the body of the file we’re uploading.
We get the uploaded data from data
and errors from err
in the callback.