Upload the file to the device download folder using Cordova FileTransfer

I am using a Cordova FileTransfer object to download a file from a URL to a 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 uploaded to data/data/com.fileDemo/files/ (I'm not sure that the download is successful, because I cannot access this folder. Receiving a success message as download complete: file:///data/data/com.fileDemo/files/sample.pdf ). How can I use the same method to upload a file to the β€œDownloads” folder of an Android device?

+6
source share
1 answer

In Cordoba with FileTransfer you can request the file system TEMPORARY or PERSISTENT

 window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, gotFS, fail); 
  • IOS
    • PERSISTENT will return a catalog of documents,
    • TEMPORARY will return the Caches directory
  • Android
    • PERSISTENT will return the root of the SD memory / phone memory
    • TEMPORARY will return the folder inside the data folder.

Refer to the File API and FileTransfer for more information.

+4
source

All Articles