Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

Downloading files in Ionic 2 using cordova-plugin-file-transfer

$
0
0

I have files (located inside the www/ folder) that I want the user to be able to download locally to their iOS/Android device.

I'm attempting to use the download method of the cordova-plugin-file-transfer, but as Ionic 2 is so new (and I'm v. new to Ionic/Angular in general) I'm unable to discover the correct paths etc.

I've managed to get it like so:

downloadFile(file) {
  this.platform.ready().then(() => {
    const fileTransfer = new FileTransfer();

    const pdfLocation = `${cordova.file.applicationDirectory}www/${file}`;
    const targetPath = cordova.file.documentsDirectory + "file.txt";

    fileTransfer.download(file, targetPath,
        (result) => {
            console.log("success");
        },
        (error) => {
            console.log("error");
        }
    );
  });
}

But I receive the "error" message each time - am I using the correct folders/approach for this?


Viewing all articles
Browse latest Browse all 228595

Trending Articles



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