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

122
Views
Ordene partes de datos asincrónicos en archivos con Dicer

Estoy analizando algunos archivos de imágenes cargados con Dicer , pero no sé cómo separar los datos en sus archivos específicos. Dado que Dicer analiza los datos de varias partes de forma asincrónica, no existe un orden en el momento en que se activan los eventos, por lo que los datos pueden aparecer en cualquier orden. Miré el objeto Dicer y no parece haber nada que identifique las partes de datos y el archivo al que pertenecen.

Código de ejemplo de Dicer:

 var inspect = require('util').inspect, http = require('http'); var Dicer = require('dicer'); // quick and dirty way to parse multipart boundary var RE_BOUNDARY = /^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i, HTML = Buffer.from('<html><head></head><body>\ <form method="POST" enctype="multipart/form-data">\ <input type="text" name="textfield"><br />\ <input type="file" name="filefield"><br />\ <input type="submit">\ </form>\ </body></html>'), PORT = 8080; http.createServer(function(req, res) { var m; if (req.method === 'POST' && req.headers['content-type'] && (m = RE_BOUNDARY.exec(req.headers['content-type']))) { var d = new Dicer({ boundary: m[1] || m[2] }); d.on('part', function(p) { console.log('New part!'); p.on('header', function(header) { for (var h in header) { console.log('Part header: k: ' + inspect(h) + ', v: ' + inspect(header[h])); } }); p.on('data', function(data) { console.log('Part data: ' + inspect(data.toString())); }); p.on('end', function() { console.log('End of part\n'); }); }); d.on('finish', function() { console.log('End of parts'); res.writeHead(200); res.end('Form submission successful!'); }); req.pipe(d); } else if (req.method === 'GET' && req.url === '/') { res.writeHead(200); res.end(HTML); } else { res.writeHead(404); res.end(); } }).listen(PORT, function() { console.log('Listening for requests on port ' + PORT); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

finalmente logré resolverlo

 d.on('part', function(p) { let image = { name: '', mime: '', data: [] }; p.on('header', function(header) { image.name = header["content-disposition"][0].split('filename="')[1].split('"')[0]; image.mime = header["content-type"][0]; }); p.on('data', function(data) { image.data.push(data); }); p.on('end', function() { time = imageReader.endStreamData(image); image = null; }); }); d.on('finish', function() { //console.log(images); res.status(200).send({response: 'ok'}); });
about 4 years ago · Juan Pablo Isaza 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!