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

242
Views
Hapi.js upload file to S3

I'm in trouble with uploading file to Amazon S3 using node.js (hapi). Here's the code of my route:

{
        method: 'POST',
        path: '/upload',
        config: {
            auth: {
                mode: 'optional',
            },
            payload:{
                maxBytes: 209715200,
                output:'stream',
                parse: true
            }, 
            handler: function(request, reply) {

                var filePath = path.join(__dirname, request.payload.file.hapi.filename);

                fs.readFile(filePath, function(err, data) {

                    console.log(data);

                    const s3 = new AWS.S3();
                    s3.putObject({
                        Bucket: 'mybucket',
                        Key: request.payload.file.hapi.filename,
                        Body: data,
                        ACL: 'public-read'
                    }, function (err) {
                        if (err) { throw err; }
                    });

                });

                reply(request.payload.file);

            }
        }
    }

What's wrong? My files uploads to the S3 cluster, but with 0 bytes size. What did I do wrong? Console.log for data returns <Buffer >

I don't know why. Can someone tell me how to fix it?

about 4 years ago · Santiago Trujillo
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!