nextcloud-java-api
nextcloud-java-api copied to clipboard
Restart logic for downloading big file
Is there any call to download the partial file from the server ?
For ex I have 1GB file and connection got lost on 800MB is there any provision to download the remaining bytes only on next call?
There is (in general) the possibility to use http range request. This is working on android with vlc to jump to positions in streaming files.
So it should be possible to do the same here.
Technically we could implement such a thing, but we have the danger that we mix things up.
For example:
- You start downloading FileA, size 650MB
- Download is aborted for some reason at 250MB
- FileA on Server is replaced with another file/content with the same size
- We now download the remaining 400MB
Now we have a mixup of two files, since it was modified on the server between the two downloads. Usually when resuming downloads, the client and server compute a hash over the already downloaded part and compare it. When they are the same a resume is allowed, otherwise the client must restart a full download. I'm not sure if NextCloud has such a thing, or if we can use some other attribute like last changed or similar
We have eTags that get changed everytime content is modified.
So workflow would be:
- start downloading, store eTag
- download fails
- on restart download, check eTag
- if eTag is still the same, compute range request, else restart from scratch
Ok,
so we need to return some sort of "restartableDownload" token in the download API, which stores the file uri/size/eTag, and then can be used to resume download if it's still unchanged.
In the same API change/extension, we could add async download/upload stuff to the library
Patches for this will be accepted ;)
In the 11.3.0 release we introduced the getProperties method to retrieve file/folder metadata. There is the etag property which allows us to detect the version of the file. Perhaps checksum can help too, but seems to not be filled in by default