You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Writing it to the phone's cache folder with the Filesystem API
So that I can then invoke the Share plugin with the file URI
I was really scratching my head for a while trying to download + read a PDF file on the web side via a FileReader, and having to coerce this into a string. I initially followed the docs and used UTF-8, which was creating an invalid PDF as PDFs are binary files.
Platform(s)
Native (not web)
Preferred Solution
Document some example code for writing binary files, not only text files. Something like this might help:
// reads a file as base64asyncreadFile(file: File): Promise<string>{returnnewPromise((resolve,reject)=>{constreader=newFileReader();reader.onloadend=()=>{if(reader.result==null){reject('No result from file reader');}if(reader.resultinstanceofArrayBuffer){reject('Unexpected ArrayBuffer');}resolve(reader.result);};reader.onerror=reject;reader.readAsDataURL(file);});}// downloads a pdf fileconstresponse=awaitfetch('https://example.com/a.pdf');constblob=awaitresponse.blob();constfile=newFile([blob],'a.pdf'{type: blob.type,});// stores it to diskconstdata=awaitreadFile(file);constres=awaitFilesystem.writeFile({data: readRes.data,directory: Directory.Cache,path: file.name,// note: no `encoding` param, so that it will write i.e. application/pdf binary data from the base64 stream, not text});
Alternatives
Additional Context
Thanks!
The text was updated successfully, but these errors were encountered:
Feature Request
Plugin
Filesystem
Description
The filesystem example code uses UTF-8 (i.e. a text encoding)
The use-case I have is:
I was really scratching my head for a while trying to download + read a PDF file on the web side via a FileReader, and having to coerce this into a string. I initially followed the docs and used UTF-8, which was creating an invalid PDF as PDFs are binary files.
Platform(s)
Native (not web)
Preferred Solution
Document some example code for writing binary files, not only text files. Something like this might help:
Alternatives
Additional Context
Thanks!
The text was updated successfully, but these errors were encountered: