Reputation: 191
I am working with cordova based hybrid application targeted to Windows 8.1 platform. I am using Visual Studio 2013 Update 4 IDE for debugging and testing. I am trying to open an image saved locally on device say "C:\image.jpg"
I tried multiple options like:
Use of window.open with file protocol as window.open("file:///C:/image.jpg");
Also tried fileopener2 plugin as
cordova.plugins.fileOpener2.open(
'C://image.jpg',
'application/jpg',
{
error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success : function () {
console.log('file opened successfully');
}
}
);
But none of them works.
Any help will be much appreciated.
Thanks, Chirag.
Upvotes: 0
Views: 657
Reputation: 452
Although it's not very well documented, cordova childBrowser doesn't support opening non-HTML files. This is due to the underlying child Browser implementation provided by Microsoft.
Either let the user pick an external app to open the file as described in this question
var applicationData = Windows.Storage.ApplicationData.current;
var localFolder = applicationData.localFolder;
console.log(localFolder);
var imageFile = "image.png";
// Get the image file from the package's image directory
localFolder.getFileAsync(imageFile).then(
function (file) {
console.log("1");
// Set the show picker option
var options = new Windows.System.LauncherOptions();
options.displayApplicationPicker = true;
// Launch the retrieved file using the selected app
Windows.System.Launcher.launchFileAsync(file, options).then(
function (success) {
if (success) {
// File launched
console.log("2");
} else {
// File launch failed
console.log("3");
}
});
});
or take a look at the Windows.Data.Pdf namespace if you'd like to try rolling your own in-app solution.
Upvotes: 0