- From: Hashbrown777 <notifications@github.com>
- Date: Thu, 10 Jul 2025 18:58:34 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/1254/3059950090@github.com>
Hashbrown777 left a comment (whatwg/fetch#1254) @AjaniBilby > Sorry to be that guy, but I just think it would be nice if I could start responding with data from the server while data from the client is still in-flight for easy UI updates is client libraries like htmx. > > The lack of proper duplex support is literally the only thing preventing me from doing nice UI updates while a file is uploaded and ingested live on a single connection - and if that connection died before the upload is completed it can easily be detected and tasks can be cancelled and/or rolledback. > > I understand this would be one hell of an undertaking for most browsers, but it would be nice if there at least an agreed goal towards this aiming vaugely at some point in the distant future. You dont need duplex to do this, you dont need the server to tell the client how much of a file is uploaded, the client is doing the uploading. I've achieved this before by using [TransformStream](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream). Basically you just get your `File` from the form or drag or filepicker, then call `.stream().pipeThrough()` your custom `.transform()` which simply passes on all chunks untouched, but reports to the UI how many bytes it has seen. This stream is what you pass to the `fetch()` and voila, you have an accurate representation of bytes being ingested by the server (because the stream would block on your end if the server blocks on it end and stops or slows in receiving data). If there are followup processing steps you want monitored then followup with another http request to receive that information. I can create a demo if you'd like. To others; fetch still needs to be duplex, there are other examples here that require it (I even need it, that's why I've been subscribed to this issue this whole time), this is just to help him out if he really needs that functionality, it's already been possible. -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/1254#issuecomment-3059950090 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/fetch/issues/1254/3059950090@github.com>
Received on Friday, 11 July 2025 01:58:38 UTC