I am trying to open a pdf file just after downloading it via cordova file transfer plugin. Even after downloading it and passing the exact same path in fileOpener2.open function, i am getting file not found. It does not matter where the file is being stored i just want the file to be displayed just after the download button click.
i tried using every cordova.file.* to set a path for download and use the same path to open but i am getting the same error since. If fileopener2 is not convenient i am okay to use another plugin just to open a downloaded pdf file. I know about the scoped storage stuff in new androids and fileopener2 is not maintained now but i want something to work as the task is extremely simple but due to lack of knowledge in android dev, i am unable to achieve this for the past 2 weeks. I want for both android and ios.
Below is my current code
function downloadFile() {
// Remote URL of the PDF file
var fileUrl =
“”;
// Local filesystem URL where the file will be saved
var targetPath =
cordova.file.externalApplicationStorageDirectory +
"CRS_Form" +
".pdf"; // You can change the target path as needed
// Check if the FileTransfer plugin is available
if (typeof FileTransfer !== "undefined") {
// Initialize the File Transfer Plugin
var fileTransfer = new FileTransfer();
// Define the options for the download
var options = {
trustAllHosts: true, // Set this to true if you're using a self-signed SSL certificate
};
// Start the download
fileTransfer.download(
fileUrl,
targetPath,
function (entry) {
// Success callback
console.log("Download success! File saved to: " + entry.toURL());
// You can perform additional actions here after successful download
cordova.plugins.fileOpener2.open(targetPath, "application/pdf", {
error: function (e) {
console.log(
"Error status: " +
e.status +
" - Error message: " +
e.message
);
},
success: function () {
console.log("file opened successfully");
},
});
},
function (error) {
// Error callback
console.error("Download error: " + JSON.stringify(error));
},
options
);
} else {
// Handle the case when the FileTransfer plugin is not available
console.error("FileTransfer plugin not available.");
}
}
getting error: file not found in the line
cordova.plugins.fileOpener2.open(targetPath, “application/pdf”, {
error: function (e)