how to download file from folder inside kubernetes container using browser ? we are using java and K8

8/7/2018

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
google-kubernetes-engine
java
kubernetes

0 Answers