Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
765 views
in Technique[技术] by (71.8m points)

android - Download a file to Downloads folder of device using Cordova FileTransfer

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
    • PERSISTENT will return the Documents directory,
    • TEMPORARY will return the Caches directory
  • Android
    • PERSISTENT will returns the root of the SD card/phone memory
    • TEMPORARY will return a folder inside the data folder.

Refer File API & FileTransfer for more info.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...