V
V
vasyok2282021-11-12 23:53:34
Node.js
vasyok228, 2021-11-12 23:53:34

How to calculate correctly parameters for Range in headers?

Hello. I'm trying to resume uploading large files after an ECONNRESET error.

let options = {
                headers: {
                    'Content-Type': 'multipart/form-data',
                    "Accept-Ranges": "bytes",
                    "Range": `bytes=${lastBytes}-${size}/${size}`
                }
              };


Bytes=${lastBytes} stores up to what size it was possible to download from the server. I take data from response.headers['content-length']
What am I specifying incorrectly in Range ? I get error 416 all the time after I start a new boot after an ECONNRESET error.
Please do not write to google or look at the documentation. Three days in a row I look at different topics, and nothing happens. Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Mirilaczvili, 2021-11-13
@2ord

1. Does the server support range at all?
2. Try to download first with wget. If it works, then at least it's possible to download it in principle. If not, then Node.js will fail.
3. It might be worth trying to limit the data retrieval rate (first with wget).

T
TheAndrey7, 2021-11-13
@TheAndrey7

`bytes=${lastBytes}-${size}/${size}`
This is generally a template string, not a mathematical expression. The server will never understand you.
https://developer.mozilla.org/ru/docs/Web/HTTP/Hea...
In your case, it will be enough Range: bytes=${lastBytes}-to check that the server understood you correctly - http status 206 should be.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question