diff --git a/front/lib/api/files/upload.ts b/front/lib/api/files/upload.ts index 54cbd264a1ef..298f2439bd23 100644 --- a/front/lib/api/files/upload.ts +++ b/front/lib/api/files/upload.ts @@ -133,7 +133,32 @@ const extractTextFromFileAndUpload: ProcessingFunction = async ( config.getTextExtractionUrl() ).fromStream(readStream, file.contentType); - await pipeline(processedStream, writeStream); + processedStream.on("data", (chunk) => { + // Handle backpressure + const canWrite = writeStream.write(chunk); + if (!canWrite) { + readStream.pause(); + writeStream.once("drain", () => readStream.resume()); + } + }); + + processedStream.on("end", () => { + writeStream.end(); + }); + + processedStream.on("error", (err) => { + throw err; + }); + + writeStream.on("error", (err) => { + throw err; + }); + + // Await the completion of the writeStream + await new Promise((resolve, reject) => { + writeStream.on("finish", resolve); + writeStream.on("error", reject); + }); return new Ok(undefined); } catch (err) {