As the title suggests I am trying to open a locally stored file – in this case a pdf. For my use case, it is required that I download the file first since it is a secured file from a web server that requires passing an authentication token in the header.
I am testing with a publicly available pdf.
var InterApp = require('FuseJS/InterApp');
var FileSystem = require("FuseJS/FileSystem");
function openPdfFromUrl(){
var path = FileSystem.cacheDirectory + "/" + "2016-NYC-Triathlon-Course-Map.pdf";
var oReq = new XMLHttpRequest();
oReq.open("GET", "http://www.nyctri.com/wp-content/uploads/2016/06/2016-NYC-Triathlon-Course-Map.pdf", true);
oReq.responseType = "arraybuffer";
oReq.onload = function (oEvent){
var arrayBuffer = oReq.response;
FileSystem.writeBufferToFile(path, arrayBuffer)
.then(function() {
console.log("Successful write");
openPdf(path);
}, function(error) {
console.log("Error while writing: " + error);
});
}
oReq.send(null);
// InterApp.launchUri("http://www.nyctri.com/wp-content/uploads/2016/06/2016-NYC-Triathlon-Course-Map.pdf");
}
function openPdf(path){
console.log("file:/" + path);
InterApp.launchUri("file:/"+path);
}
It successfully writes the file but has trouble trying to open it on Android. I have not tested on iOS. The file is written to the file system correctly and can be opened outside of the app. I have tried with “file://”+path and have gotten a different error. The path as it is now resolves to: “file://storage/emulated/0/Android/data/com.apps.openingfiles/cache/2016-NYC-Triathlon-Course-Map.pdf”. Is this a limitation of InterApp and will I need to figure something out in Uno? Thanks!