问题
I'm using Cordova/Phonegap and I want to use a plugin for download a file and put it in Downloads folder. I find the plugin FileTransfer http://docs.phonegap.com/en/edge/cordova_file_file.md.html#FileTransfer
I'm using this plugin but I don't known the path of folder Download in every device another i want to use the native notification of device...I read that I download the file from remote server but I don't where is and don't show the native console...this is my code in my controller
var fileTransfer = new FileTransfer();
var uri = encodeURI("http://someUrl/tost.pdf");
var fileURL = "/sdcard/Download/tost.pdf";
fileTransfer.download (uri, fileURL, function(entry) {
console.log("download complete: " + entry.toURL());
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
false,
{
headers: {
//"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
}
);
Do you know how I can use it with the native notification and the correct path where I must download it?
回答1:
If you look at the apache/cordova-plugin-file github you can see the locations where you can read from and write to listed in tables for iOS, Android and Blackberry 10.
From the looks of it you are trying to download to a sdcard on Android? The correct url would look like this:
var fileURL = cordova.file.externalRootDirectory+"Download/tost.pdf";
I'm guessing you want to develop you app for iOS and Android, so you should use this url:
var fileURL = cordova.file.dataDirectory+"Download/tost.pdf";
since it's a valid url on both and it's persistent and private.
来源:https://stackoverflow.com/questions/31021690/cordova-phonegap-file-transfer-plugin