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]
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; };