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

210
Vistas
How do I pipe a file from S3 to the client in Uint8List format in Node.js?

I am currently working on a Api just to get to know Node.js, as I am currently learning it.

I successfully created a route for uploading an mp3 file into an s3 bucket, but when I try to fetch a file from S3 in Uint8List format, I don't get the results I want. (Flutter requires me to send an Uin8List, if this is not a good solution I can also convert it into an Ui8List on the client side)

I am able to create a Readable stream, and when the stream receives chunks it logs it into the console. But I am not quite sure how I can send the data back to the client in buffers, I am only able to send the data in one big list but ofcourse for efficiency this is not the best option.

Anyone able to help me? This is the code is currently have:

    var AWS = require('aws-sdk');
    
    AWS.config.update(
        {
            accessKeyId: AWS_ACCESS_KEY,
            secretAccessKey: AWS_SECRET_ACCESS_KEY,
            region: AWS_REGION
        }
    );
    
    var s3 = new AWS.S3();   

 

router.get('/assets/:fileKey', auth, async function (req, res, next) {
        try {
            const fileKey = req.params.fileKey;
    
            const options = {
                Bucket: AWS_BUCKET_NAME,
                Key: fileKey,
            };
    
            const chunks = [];
    
            const getAsBytes = new Promise((resolve, reject) => {
                const readStream = s3.getObject(options).createReadStream();
    
                readStream.on('data', (chunk) => {
                    // console.log('-------new data received--------')
                    // console.log(chunk);
                    chunks.push(chunk);
                    // res.write(chunk);
                });
    
                readStream.on('error', reject)
    
                readStream.on('end', resolve);
            }).catch((err) => next(err));
    
            await getAsBytes;
    
            res.write(Uint8Array.from(chunks));
            res.end();
    
    
        } catch (error) {
            next(error);
        }
    });

When I try to pipe the readstream I get a response full of question marks and weird symbols..

about 4 years ago · Juan Pablo Isaza
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