Skip to content

Allow a ReadableByteStream in fetch({body: <body>}) #577

Closed
@ConradIrwin

Description

@ConradIrwin

I'd like progress events on uploads. I think this should work according to the current spec, but it doesn't seem to work in practice, as I'm not sure how to tell the fetch "how much stream" it should read.

  function upload (url, blob, onUploadProgress) {
    let progress = 0
    let readableByteStream = new ReadableStream({
      type: 'byte'
      pull: function (controller) {
        onUploadProgress({todo: blob.size, done: progress})
        let nextProgress = progress + controller.desiredSize
        controller.enqueue(@blob.slice(progress, nextProgress))
        progress = nextProgress
      }
    })

    return fetch(url, {
      mode: 'cors'
      method: 'POST'
      headers: {'Content-Type': blob.type}
      body: readableByteStream
    })
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions