0

We have web application with client in agnular.js and server in java. we have deployed this application docker container. Now our applicaton logs are created at location /var/tmp/logs.tar.

Our use case is to give end user facility of downloading this log file i.e. logs.tar currently we are giving this download facility on client on click of button but using Blob octet-stream. our issue is in case this log size becomes huge in some GB then while streaming it will create load on application memory. so we want to give functionality where instead of streaming an external link will be there from which file will get directly downloaded on click of button. we want to do this using the code as an application functionality.

Server side function -

public File downloadLogs() {
        File file = null;
        try {
            executor.execute("/bin/sh", "-c", mcmProp.getKeyValue("download.log.script.location"));
            String filePath = "/var/tmp/logs.tar";
            file = new File(filePath);
            logger.debug("File exist for download");
            return file;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

Client side code -

 this._service.downloadLogs().subscribe(
            success => {               
                var blb = new Blob([success], { 'type': "application/octet-stream" });
                if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                    window.navigator.msSaveOrOpenBlob(blb, 'logs.tar');
                }
                else {
                    var link = document.createElement('a');
                    link.href = window.URL.createObjectURL(blb);
                    link.download = "logs.tar";
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                }
            });
questp
  • 133
  • 1
  • 3
  • 11
  • If you want to download the log from the browser, transferring it as `application/octet-stream` via HTTP(S) is the most direct way you will ever get. However, streaming should _not_ create load on the memory. If it does, the code that performs this streaming is doing something wrong. The amount of memory consumed should just be a buffer size, like 4K or 8K or so. The code should not load the entire blob into memory, that's unnecessary. – Christian Hujer Aug 07 '18 at 09:02
  • just updated description with my code. Can you please guide if we are doing some thing wrong...Do you have any link or example where blob is not entirely into memory for downloading... – questp Aug 07 '18 at 09:20
  • How is function downloadLogs called? – Christian Hujer Aug 07 '18 at 09:22
  • client side code this._service.downloadLogs().subscribe....... calls the serverside downloadLogs function – questp Aug 07 '18 at 09:23
  • Please suggest if you have any example where entire blob is not getting loaded entirely into the memory. – questp Aug 07 '18 at 09:44
  • I still can't answer because I still don't know _how_ `downloadLogs()` is called. Is `downloadLogs()` a Spring Controller method, or what? – Christian Hujer Aug 07 '18 at 23:26
  • Hi Christian Hujer, Thanks for your reply. I have better explained issue at following url, Can you please have look and guide me. Actually my main issue is i am able to download file but every time i download file file size is getting added to browser memory. I want to reduce browser memory size consumed equal to buffer size. please guide what changes i need to do in client of server - https://stackoverflow.com/questions/51725818/how-to-download-large-files-chunk-by-chunk-using-large-files-using-angular-js-an/51727618?noredirect=1#comment90440888_51727618 – questp Aug 08 '18 at 10:24
  • Possible duplicate of [how to download large files chunk by chunk using large files using angular.js and java](https://stackoverflow.com/questions/51725818/how-to-download-large-files-chunk-by-chunk-using-large-files-using-angular-js-an) – Jason Aug 08 '18 at 23:49

0 Answers0