0

I am creating a servlet that makes files to client downloadable. I achieved this but not able to make that resumable downloads to the client.

Here is my code

private void startDownloadProcess(File file) {
    this.response.addHeader("Accept-Ranges", "bytes");
    this.response.setContentType("APPLICATION/OCTET-STREAM");
    this.response.setContentLength((int) file.length());
    this.response.setHeader("Content-disposition", String.format("attachment; filename=%s", file.getName()));
    try (ServletOutputStream outputStream = this.response.getOutputStream()) {
        try (FileInputStream inputStream = new FileInputStream(file)) {
            byte[] buffer = new byte[8072];
            int len;
            while ((len = inputStream.read(buffer)) > 0) {
                outputStream.write(buffer, 0, len);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

This code will make the download available but the client is not able to pause and resume the downloads.

Chirag
  • 555
  • 1
  • 5
  • 20
  • What does "not able to make that resumable" mean? What is the problem you're facing? What have you tried? – JB Nizet Jul 04 '18 at 16:36
  • means the download does not support pause and resume – Chirag Jul 04 '18 at 16:38
  • 2
    That won't happen magically. You need to add some code to support that. Your current code claims that it accepts range requests. That's not sufficient: you actually need to add the code to correctly handle range requests, i.e. requests with the Range header. Read the documentation (https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests) and try something. – JB Nizet Jul 04 '18 at 16:41

0 Answers0