Skip to content Skip to sidebar Skip to footer

File-transfer Download File Issue On Cordova 3.1

I'm creating my first webapplication using cordova 3.1. In this app I need to be able to download a file to the phone and then open it, but i cant seem to get pass how to download

Solution 1:

Not sure about 3.1, but for the latest version of Cordova (3.3+), the newer (1.0.0+) version of File uses filesystem URLs instead of the file path. Something like this:

cdvfile://localhost/persistent/path/to/file

See the notes at the bottom of this doc: https://github.com/apache/cordova-plugin-file-transfer/blob/31ac00d3ae35f9ca280cf4e6c9edc9df23ea95b5/doc/index.md


Solution 2:

cordova 3.3.0 cordova-plugin-file-transfer r 0.4.2 cordova-plugin-file r 1.0.1

TESTED on real devices, works both for Android and iOS

my code:

fileTransfer.download(
    "http://my.domain.com/data/sashaTest.txt",
    fileSystem.root.toURL() + "sashaTest.txt", // the key factor !!!
    function(theFile) {
    alert("download complete: " + theFile.toURL());
    console.log("download complete: " + theFile.toURL());
    },
    function(error) {
    console.log("download error source " + error.source);
    console.log("download error target " + error.target);
    console.log("upload error code: " + error.code);
    },
    true
);

the target set to: fileSystem.root.toURL() + "sashaTest.txt",

made the difference.


Solution 3:

yup, fileSystem.root.toURL() is the new player out there and lets you use the latest cdvfile:// url system of Cordova.

Too bad they didn't shared a general notice on this right away. It showed up in a resolved issue's comments and later was documented on the documentation in their GIT repo as dsims mentioned earlier.

Once the toURL() thing is clear the download samples as Phonegap/Cordova docs state make sense and will work out.


Solution 4:

Add the Internet Permission also

<uses-permission android:name="android.permission.INTERNET" />

Post a Comment for "File-transfer Download File Issue On Cordova 3.1"