Reputation: 1
Alright so I've downloaded the plugin from the Monaca/Cordova plugin repository. Then I added the javascript from the FileTransfer plugin site for the download and replaced the encodeURI with the file path.
https://www.npmjs.com/package/cordova-plugin-file-transfer#download
<script>
var fileTransfer = new FileTransfer();
var uri = encodeURI("http://www.ulc.org/wp-content/uploads/2012/09/King-James-Bible-KJV-Bible-PDF.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=="
}
}
);
</script>
I'm trying to call it with an onclick function using html..
<button onclick="FileTransfer()">Download</button>
It doesn't work though, how can I get the file to download onclick to their device?
Upvotes: 0
Views: 878
Reputation: 1
First, your uri not download automacally.
Try:
var pdfFileUrl = "https://wogopezup2016.files.wordpress.com/2016/04/giao-an-dien-tu-tieu-hoc.pdf";
Second, please define "fileURL" parameter.
Try:
'/storage/emulated/0/path/to/'; // For Android
cordova.file.documentsDirectory; // For ios
Upvotes: 0