Esente
Esente11mo ago

Streaming FormData

I have Deno.serve a HTML page with <form enctype="multipart/form-data"> with a file input. I also have a handler for POST that would take that File, split it, and sends the chunks to another endpoint. What I have so far in the POST handler is to await request.formData() to retrieve the File from there and split. It works fine for small files, but for big file, the handler would wait until the whole file is sent before starting to split, which can overflow the memory. Is there a way that I can immediately stream the File from the browser's request, and split it as more data come in?
3 Replies
Andreu Botella (they/them)
there's currently no way to do this, other than by parsing the multipart/form-data format by yourself I suppose there must be third-party libraries for that adding a web API to allow that is somewhere on the todo list of the WinterCG project, but it's low priority
Esente
Esente11mo ago
I see. Thanks! I will look for some library.
Esente
Esente11mo ago
Just some information I stumbled upon: https://github.com/nodejs/undici/issues/974
GitHub
Implement multipart parsing · Issue #974 · nodejs/undici
Our extractBody method is missing support for parsing multipart/form-data responses.