Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48980

Ionic file download not working in app working on browser

$
0
0

Hi All,

I am just checking on any file download from server.

Below code is working on browser but not in APP.
Seems that below code not working

document.body.appendChild(downloadLink);
downloadLink.click();

My full code:-

downloadFile(directory: string, filename: string = null): void {

    const baseUrl = this.service.Base_Url + 'download.php?dir=files/' + directory + '/&file=' + filename;

    this.service.process_download(baseUrl).subscribe(

      (response: any) => {

        //Check Blob size | File is available or not

        if (response.size > 0) {

          let dataType = response.type;

          let binaryData = [];

          binaryData.push(response);

          let downloadLink = document.createElement('a');

          downloadLink.href = window.URL.createObjectURL(new Blob(binaryData, { type: dataType }));

          if (filename) {

            downloadLink.setAttribute('download', filename);

          }

          document.body.appendChild(downloadLink);

          downloadLink.click();

        }

      }

    )

  }

Please suggest on this.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48980

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>