Reputation: 1322
I am trying to upload a files to the s3 bucket,The following code I am using to accomplish this operation.
var params = {
localFile: "../Processor/1.wav",
s3Params: {
Bucket: "bucketname",
Key: "1.wav",
},
};
var uploader = client.uploadFile(params);
uploader.on('error', function(err) {
console.error("unable to upload:", err.stack);
});
uploader.on('progress', function() {
console.log("progress", uploader.progressMd5Amount,
uploader.progressAmount, uploader.progressTotal);
});
uploader.on('end', function() {
console.log("done uploading");
});
Every thing works fine till this point. Now lets say here, I want to upload 5 files from local path to s3 bucket, How can I achieve that is there any direct method providing amazon for multiple file uploads or I need to use async module.?
Upvotes: 11
Views: 8618
Reputation: 465
The NodeJS AWS SDK doesn't have any bulk S3 upload method, I'd suggest you to use async/await to upload multiple files at once. Here's an example:
const s3 = new AWS.S3()
const params = [
{ Bucket: 'bucket', Key: 'key', Body: 'body' },
{ Bucket: 'bucket', Key: 'key2', Body: 'body2' },
{ Bucket: 'bucket', Key: 'key3', Body: 'body3' }
]
const responses = await Promise.all(
params.map(param => s3.upload(param).promise())
)
console.log(responses)
Upvotes: 9