whatwg-streams-api

Streaming a client-side generated response as a download, without service worker

♀尐吖头ヾ 提交于 2021-02-11 15:31:43
问题 Suppose I have a large file I generate client-side that I want to allow the user to save to their hard drive. The usual method would be to create a Blob, and then create an object URL for it: const blob = new Blob([chunks], {type: 'application/example'}); linkEl.href = URL.createObjectUrl(blob); This works, but isn't very efficient as it can quickly exhaust all available memory, since the resulting file has to remain in memory. A better method would enable streaming. Something like this:

How to get File upload progress with fetch() and WhatWG streams

好久不见. 提交于 2019-12-21 07:35:16
问题 Note: I'm not looking for any alternatives. I know this can be done with XMLHttpRequest. I also don't care about browser support. I just want learn about the new/upcoming standards. I have a File object and I can upload it with PUT using fetch like this: fetch(url, { method: "PUT", body: fileObject, }); How can I get upload progress from this? From what I understand the body of the fetch options can be a ReadableStream. So maybe there is a way to wrap the File object to a ReadableStream and

Fetch with ReadableStream as Request Body

我是研究僧i 提交于 2019-11-26 20:38:17
I'm trying to use fetch with a ReadableStream . In this example, the ReadableStream should simply repeat "Some data..." indefinitely. fetch('/', { method: 'POST', body: new ReadableStream({ pull: function(controller) { console.log('pull called!'); controller.enqueue('Some data...'); } }) }); This doesn't work. While pull is executed once, no data is sent in the request body. POST / HTTP/1.1 Host: example.com Connection: keep-alive Content-Length: 0 Origin: https://example.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari

Fetch with ReadableStream as Request Body

眉间皱痕 提交于 2019-11-26 07:37:25
问题 I\'m trying to use fetch with a ReadableStream. In this example, the ReadableStream should simply repeat \"Some data...\" indefinitely. fetch(\'/\', { method: \'POST\', body: new ReadableStream({ pull: function(controller) { console.log(\'pull called!\'); controller.enqueue(\'Some data...\'); } }) }); This doesn\'t work. While pull is executed once, no data is sent in the request body. POST / HTTP/1.1 Host: example.com Connection: keep-alive Content-Length: 0 Origin: https://example.com User