Reputation: 69
I have created one app. in which i want the feature to download pdf
http://www.premah.com.au/monthly-updates/
Now, when I redirect to this app from mobile's browser.i can download pdf when i click on any of pdf's poster. But When i am using phoneGap build to do this.Unable to download pdf i have tried following : 1. inappBrowser using window.open with _blank,_system. 2. i have tried using file-transfer plugin for downloading from absolute url of server for ex:
http://www.premah.com.au/wp-content/uploads/2013/04/apr-2014-gen-f.pdf
If you have any 100% working solution for inAppbrowser or file-transfer plugin please put code.
Many thanks in advance.
Upvotes: 0
Views: 787
Reputation: 23891
You can use file-transfer cordova plugin.
https://github.com/apache/cordova-plugin-file-transfer
var fileTransfer = new FileTransfer();
var uri = encodeURI("http://www.premah.com.au/wp-content/uploads/2013/04/apr-2014-gen-f.pdf");
fileTransfer.download(
uri,
filePath,
function(entry) {
console.log("download complete: " + entry.fullPath);
},
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=="
}
}
);
Upvotes: 0
Reputation: 1319
source = http://www.premah.com.au/wp-content/uploads/2013/04/apr-2014-gen-f.pdf
fpath = YOUR_FILE_PATH; //use filesystem to get file path.
downloadBook: function(source, fpath)
{
var fileTransfer = new FileTransfer();
fileTransfer.download(source,fpath,function(entry) {
},
function(error) {
console.log("download error target " + error.code);
});
}
Upvotes: 0