Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48979

Ionic save and load pdf from filesystem

$
0
0

Hi all, I need help because I’m not able to write and read a file.

the code is very simple

this function save a hello world pdf

async savePDF(pdfString, filename) {
try {
const result = await Filesystem.writeFile({
path: ‘/’ + filename,
data: pdfString,
directory: FilesystemDirectory.Documents,
encoding: FilesystemEncoding.UTF8
})
console.log(‘Wrote file’, JSON.stringify(result));
return result;

} catch(e) {
  console.error('Unable to write file', e);
}

}

and all works fine. I see the message ‘wrote file’.

The issue is when I try to read the file:

readFile() {

this.savePdf().then((val) => {

const path = val.uri;
const mimeType = 'application/pdf';

this.fileOpener.showOpenWithDialog(path,mimeType)
.then(()=> console.log('file opened ' + val.uri))
.catch((e)=>console.log('file open error ' + JSON.stringify(e)))

})

}

I always get error

{“status”:9,“message”:“File not found”}

What I’m doing wrong? could you help me?

thanks

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48979

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>