Hi there, I’m hoping this is posted in the right section, but please feel free to let me know if i should re-open the topic in another thread if it is best off somewhere else.
The Question: Is there a way to transfer a file from:
assets/folder/file.pdf
to:
file.dataDirectory() (the native directory for files to go)
Currently i have the following code, with a file (say file.pdf) located in ‘assets/folder/file.pdf’ which i am hoping to bring the ‘open with’ section in iOS/android up such that the file can be opened in another PDF filler app such as adobe reader. After scouring the web, it seems my best bet is with the ‘cordova-file-opener2’ plugin which specifically allows for opening files in external applications. However one of the slight issues that happens with this plugin is that files must be opened from a native storage location, and not the ‘assets/folder’ folder, hence my need to get the PDF currently residing in ‘assets/folder’ to the native folder.
CODE so far:
this.file.checkFile(this.file.dataDirectory, 'file.pdf').then((result:boolean) => {
//annoying quirk with plugin means 'result' wont return false, instead i have to use catch to know the file doesn't exist
}).catch((err) => {
this.file.moveFile('assets/folder/', 'file.pdf', this.file.dataDirectory, 'file.pdf').then(() => {
this.fileOpener.open(this.general.dataDirectory + 'file.pdf', 'application/pdf').then(() => {
alert('success');
});
});
});
I also have catch blocks put onto the code to alert out any errors, and am currently getting the following:
{"code":5,"message": "ENCODING_ERR"}
from the .moveFile() section of the code, to which i assume is due to not finding file.pdf in question. Now i understand that the documentViewer plugin allows the same functionality, however i am hoping to just show the open in file straight away rather than showing a blank file and hoping the user will click the ‘share’ arrow in the top right to open in another application (Bad UX).
Alternatively if there is a way to get the file.pdf straight into storage without having to transfer it from the assets folder first, i assume this would work too.
Any help to get this issue sorted is much appreciated in advance. Thank you.