- From: Marius <notifications@github.com>
- Date: Sun, 10 Sep 2023 23:54:08 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/1626/1713275711@github.com>
> what if someone wants to manually stop/pause With resumable uploads, a pause is just an aborting of the currently running HTTP request. Therefore, one option would be to reuse the abort controller that is already available in the Fetch API: ```js const controller = new AbortController(); const signal = controller.signal; fetch(url, { method: "POST" body: file, resumable: true, signal }); // Stop the upload controller.abort(); ``` > You would have to create a Request first before you could do the actual request. I am not sure if there is interest in using a method on the Request type to trigger a new HTTP request. Another option is to not reuse the previous fetch instance and instead create a new request that carries over some resumption information from the previous request. That's similar how Apple implemented resumable uploads in `URLSession` on iOS: ```js try { await fetch(url, { method: "POST" body: file, resumable: true, }); } catch (err) { const resumeData = err.getResumeData() if (resumeData != null) { await fetch(url, { method: "POST" resumeData, }); } } ``` `err.getResumeData()` could return some opaque data type that carries information about the upload URL and the file to be uploaded. By passing this information from the previous fetch call to the next one, enough information is available to resume the upload. -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/1626#issuecomment-1713275711 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/fetch/issues/1626/1713275711@github.com>
Received on Monday, 11 September 2023 06:54:15 UTC