Downloads to SD without the body ever passing through the browser. Use it for books, images and anything over 64 KB.
const res = await api.fetchToSd(
'https://example.com/book.epub',
'/Books/Example/book.epub',
{ Authorization: 'Bearer ' + token });
// res = { status: 200, bytes: 1234567, complete: true, total: 1234567 }
- dest must be absolute, without ... Missing parent folders are created.
- Writes to dest.part first and replaces dest only when complete, so a failed update keeps the old file.
- GET (the default): follows up to 5 redirects, resumes after network drops with Range requests, and transfers in 2 MB segments so mobile browsers don't kill long requests. Your headers are sent only while redirects stay on the same scheme+host+port.
- Other methods / a body: options = { method: 'POST', body: '{"x":1}' }. Body <= 4 KB, sent once, no redirects, no resume.
- On failure it throws. err.result holds the device answer, e.g. {status: 404, error: 'http status', complete: false}. For non-GET requests err.result.body contains the first 512 bytes of the server's error answer.
- Saving .epub, .txt, .md or .xtc (outside hidden folders) marks the Library index stale, so the book shows up the next time the Library opens.