Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic 3 - file download with FileTransfer not working

In an angular/ionic app, I have the following code to download a pdf from the internet.

public pdfDownload(){
        const fileTransfer: FileTransferObject = this.transfer.create();
        const mime = 'application/pdf';
        const pdfFile = 'http://www.pdf995.com/samples/pdf.pdf';
        // alert(this.file.dataDirectory);
        fileTransfer.download(pdfFile, this.file.dataDirectory + 'file.pdf', true)
            .then((entry) => {
                alert('download complete: ' + entry.toURL());
            }, (error) => {
                // handle error
            });
    }

But now Im looking for this file in my android phone but I cant find it. The path in my phone is enter image description here There are no files. Where did I download it?

like image 301
gerl Avatar asked Feb 01 '26 02:02

gerl


1 Answers

Use this.file.externalDataDirectory+'file.pdf' instead of this.file.dataDirectory+'file.pdf' in second parameter of function fileTransfer.download(1 parameter,2 parameter,3 parameter);

e.g.

fileTransfer.download(pdfFile, this.file.externalDataDirectory + 'file.pdf', true)

like image 133
Prem popatia Avatar answered Feb 03 '26 19:02

Prem popatia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!