Skip to content

Instantly share code, notes, and snippets.

@devgeeks
Last active January 17, 2023 15:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save devgeeks/4982983 to your computer and use it in GitHub Desktop.
Save devgeeks/4982983 to your computer and use it in GitHub Desktop.
Example file download and open in Cordova inAppBrowser
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, gotFS, fail);
function fail(error) {
console.log(error)
}
function gotFS(fileSystem) {
fileSystem.root.getDirectory("data", {create: true, exclusive: false}, gotDir, fail);
}
function gotDir(dirEntry) {
dirEntry.getFile("unixtoolbox.pdf", {create: true, exclusive: false}, gotFile, fail);
}
function gotFile(fileEntry) {
// Start FileTransfer here...
var fileTransfer = new FileTransfer();
var uri = encodeURI("http://cb.vu/unixtoolbox.pdf");
fileTransfer.download(
uri,
fileEntry.fullPath,
function(entry) {
//window.plugins.webintent.startActivity({
// action: WebIntent.ACTION_VIEW,
// url: encodeURI(entry.fullPath),
//}, function () {}, function (error) {
// console.log(error);
//});
window.open(encodeURI(entry.fullPath),"_blank","location=no,enableViewportScale=yes")
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);
}
);
}
@devgeeks
Copy link
Author

This works in iOS, but not so much in Android.. passing off a file requires there to be something to receive it.

Might have to catch some errors and make suggestions.

@identy
Copy link

identy commented Jan 18, 2016

"_system" target

@khairilazizee
Copy link

can i use this script in intel xdk?

@NickSchneiderIsTired
Copy link

NickSchneiderIsTired commented Sep 19, 2019

Where to put this file? The webapp source folder or some cordova folder?

@rohitattaluri
Copy link

@Steakie

Where to put this file? The webapp source folder or some cordova folder?

Hey, you can use this function where you want to use download feature in your application.

i.e: We should be using this in our application but not in cordova folder.

@rohitattaluri
Copy link

what exactly the plugins do we need while using this code ? @devgeeks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment