Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

559
Views
How to upload multiple files which are stored as buffer to s3 bucket using node js

I have unzipped the zip files to buffer. Now I need to upload those unzipped files from buffer to S3 bucket using Node.js. How do I do that?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Hope this will help, Just loop on your unzipped files and send each

var AWS = require('aws-sdk');
var fs = require('fs');


module.exports.UploadFile = function(credentials, BucketPath, folder, Region, fname, s3url, req, res, callback) {
        // AWS Region
        AWS.config.region = Region;
        // AWS credentials
        AWS.config.update(credentials);

        // create read stream for file
        var filestream = fs.createReadStream(fname);
        //create an instance of s3
        var s3 = new AWS.S3({params: {Bucket: BucketPath}});
        // read file
        fs.readFile(fname, function (err, data) {
        //upload to s3
        s3.upload({ Key: folder + fname
                  , Body: filestream
                    // change contentType as needed
                  , ACL: 'public-read','ContentType' : 'application/pdf'}
                      , function(err,result) {
                       if(err) throw err;
                       // check if the file uploaded or not
                       s3.getObject({ Key: folder + fname },
                        function (error, data) {
                        if (error != null) {

                        } else {
                            // remove file from local if needed
                            fs.unlink(fname, function (err) {
                           if (err) {
                               console.log(err);
                           }
                           callback("", data);

                       });
                       }
                    });

           });
        });
};
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!