0

When I'm trying to download a file say of some 900 MB and when I pause download and retry after some time (say hours). Chrome instead of resuming the download just marks the file as completed.

 public HttpURLConnection getConnection(String url, METHOD method)
            throws IOException, SocketException {
        URL server = new URL(url);
        HttpURLConnection httpsconnection = (HttpURLConnection) server.openConnection();
        if (method == METHOD.POST) {
            httpsconnection.setRequestMethod("POST"); //No i18N
            httpsconnection.setFixedLengthStreamingMode(0);
        } else if (method == METHOD.GET) {
            httpsconnection.setRequestMethod("GET"); //No i18N
        }
        httpsconnection.setDoInput(true);
        httpsconnection.setDoOutput(true);
        httpsconnection.setInstanceFollowRedirects(false);
        httpsconnection.setRequestProperty("connection","keep-alive"); //No i18N
        httpsconnection.setRequestProperty("content-length","0"); //No i18N
        httpsconnection.setConnectTimeout(4000);
        httpsconnection.setReadTimeout(30000);
        return httpsconnection;
    }

Am I missing something to set in the header value. When I tried downloading the file from other websites they simply say "Network - Disconnected" and pauses the download which could be resumed after sometime.

Just curious how this pause and resume works with chrome. How my browser client (like Chrome, Firefox) knows about the network interruption. Can someone enlighten me on this?

  • I think the technology you're looking for is [`Accept-Ranges`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Ranges) and [`Range`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range), but I think they might be a bit difficult to implement. Some info [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests). – Karl Reid Dec 04 '17 at 11:59
  • @KarlReid This just allows the client to fetch the file in a specific range. Say for example in a 100MB file the `Range` header allows the browser to fetch bytes in specific range (eg; like from 1024 byte to 2048 bytes). –  Dec 04 '17 at 12:15
  • Some how the browser should not allow to mark the file as complete (when the file hasn't downloaded completely) - is it possible to handle at my server by setting some header value which the browser can understand? –  Dec 04 '17 at 12:16
  • `This just allows the client to fetch the file in a specific range` - yes, but the point is that this functionality is actually how resumable downloads are implemented. When Chrome resumes, it uses `Range` to ask only for the part of the file that it hasn't already downloaded before the connection failed. Chrome knows the file isn't complete based on the `Content-Length`. It's described [here](https://superuser.com/a/332926). I'm pretty sure to support this resumable download behaviour, your server needs to be able to handle Ranges. – Karl Reid Dec 04 '17 at 13:29
  • will take a look @KarlReid... –  Dec 04 '17 at 13:59
  • @KarlReid : It's exactly what you said. It just tries to resume the download with the help of `Accept-Ranges` header - which implies that the server is capable of supporting range requests and also when it passes the validation - which means when the download is resumed - there has to be some validation - that it is resuming the same file again - which could be done with the help of `Last-Modified` or `ETag` headers. Thanks a lot :-) –  Jan 06 '18 at 16:43
  • And this could be the proper implementation (when supporting range requests) - so that the download could be continued after interruption or break... –  Jan 06 '18 at 16:44
  • But ideally chrome shouldn't mark the partially downloaded file as completed. So,I've filed a bug here (https://bugs.chromium.org/p/chromium/issues/detail?id=795736&can=2&q=&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified&groupby=&sort=&hotlist_id=) –  Jan 06 '18 at 16:45

0 Answers0