I am downloading a file from DropBox.
I can see that the file exists by using File.exists(filePath)
and it returns true
.
But I am not able to open the file (with the default application) with either File.fromPath(filePath)
or with openUrl(filePath)
.
Here is my code:
HomePage.prototype.getDownload = function() {
var filePath = fs.path.join(fs.knownFolders.currentApp().path, "MyFile");
httpModule.getFile({
url: "https://content.dropboxapi.com/2/files/download",
method: "POST",
headers: { "Content-Type": "", "Dropbox-API-Arg": JSON.stringify({"path": "/MyFolder/MyFile"}), "Authorization": "Bearer *********" },
}, filePath).then(function (response) {
console.log("file exists: "+fs.File.exists(filePath)); // This return true
// tried this
fs.File.fromPath(filePath); // Does nothing
// tried this
utilsutils.openUrl(filePath); // Does nothing
}
AFAIK openUrl
works only for web links and cannot be used to open local files. And fs.File.fromPath(filePath);
just creates instance of File and does not do anything with it
In order to open the file you need to use the native APIs available for each platform. For example for android (assuming your file is PDF):
try
{
var intent = new android.content.Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(android.net.Uri.fromFile(new java.io.File(filePath)), "application/pdf");
application.android.currentContext.startActivity(android.content.Intent.createChooser(intent, "Open PDF..."));
}
catch (e)
{
console.log("Missing PDF application");
}