Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

248
Vistas
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?

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda