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

202
Views
Cómo convertir async AsyncIterable<Uint8Array> a archivo en Javascript

Hola, estoy enviando/PUBLICANDO un archivo desde un formulario HTML en un cliente de navegador a un servidor de aplicaciones Remix.

El servidor de aplicaciones Remix está enviando/manejando mi archivo como un AsyncIterable asíncrono. Ahora necesito volver a convertirlo en un objeto de archivo para poder enviarlo a un servidor backend como FormData.

Probé con y sin búfer para la demostración:

¿Alguien tiene experiencia con convertir AsyncIterable a Blob y luego a File?

 const myHandler: UploadHandler = async ({ name, contentType, data, filename }) => { //'data' is data of type AsyncIterable<Uint8Array> //'contentType' is 'image/png' let dataArray1 = []; //test1 without buffer let dataArray2 = []; //test2 with buffer for await (const x of data) { dataArray1.push(x); //without buffer dataArray2.push(x.buffer); //with buffer } const blob1 = new Blob(dataArray1, {type: contentType}); const blob2 = new Blob(dataArray2, {type: contentType}); const file1 = new File([blob1], filename, { type: contentType }); const file2 = new File([blob2], filename, { type: contentType }); console.log('file1.size: ', file1.size); //file1 size is 1336843 (and for file2) //but i'm getting content-length 1337028 from my browser Form //so I'm not sure if it's correct return file1; };

[![tamaño de la longitud del contenido][1]][1]

[![ingrese la descripción de la imagen aquí][2]][2]

[![ingrese la descripción de la imagen aquí][3]][3]

[![ingrese la descripción de la imagen aquí][4]][4]

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Intente pasar las partes del blob directamente al constructor de archivos.

 const myHandler: UploadHandler = async ({ name, contentType, data, filename }) => { const dataArray1 = []; for await (const x of data) { dataArray1.push(x); } const file1 = new File(dataArray1, filename, { type: contentType }); return file1; };
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!