I am using Cordova FileTransfer object to download a file from a url to device.
var fileTransfer = new FileTransfer();
var path = cordova.file.dataDirectory;
 fileTransfer.download(
        fileUrl,
        path + "/sample.pdf",
        function(theFile) {
            console.log("download complete: " + theFile.toURI());
            alert("File downloaded to "+cordova.file.dataDirectory);
        },
        function(error) {              
            console.log(JSON.stringify(error));
        }
    );
In this case the file is downloaded to data/data/com.fileDemo/files/
(I am not sure whether download is success as I can't access this folder. Getting success message as download complete: file:///data/data/com.fileDemo/files/sample.pdf).
How can I use the same method to download a file to "Downloads" folder of the android device?
In Cordova, with  FileTransfer, you can request TEMPORARY or PERSISTENT file system
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, gotFS, fail);
- iOS
PERSISTENTwill return the Documents directory,
TEMPORARYwill return the Caches directory- Android
PERSISTENTwill returns the root of the SD card/phone memory
TEMPORARYwill return a folder inside the data folder.
Refer File API & FileTransfer for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With