[whatwg/fetch] upload file progress traking not working (Issue #1380)

I am uploading a file using fetch streams, but I need can calculate the upload progress. 

On the server I receive an corrupt file of 0 bytes, I really don't know how to use the ReadableStreams correclty, I am doing something wrong?.

Browser code

```js
const fileReadble = (reader) => new ReadableStream({
  start(controller) {
     return pump()
      function pump() {
        return reader.read().then(({ done, value }) => {
          if (done) {
              controller.close()
              return
          }
          // i think implement file upload traking here
          controller.enqueue(value)
          return pump()
        })
      }
  }

const uploadVideo = async (file) => {
    const fileReader = file.stream().getReader()
    const response = await fetch('http://localhost:3005', { 
      method: 'POST',   
      body: fileReadble(fileReader),
    })
  
    if (!response.ok) {
      console.error(`unexpected response ${response.statusText}`)
      return
    }
}
}) 
```

Server code (Node.js)

```js
import http from 'node:http'
import { createWriteStream } from 'node:fs'

http
  .createServer((req) => {
    if (req.method !== 'POST') return
    req.pipe(createWriteStream('./video.mp4'))
  })
  .listen(3005)
```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1380
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/issues/1380@github.com>

Received on Monday, 3 January 2022 06:50:12 UTC