Read binary file located in project directory using @ionic/react-hooks/filesystem

Hi guys. I want to read a docx file inside my src (or even assets. no mattar) in runtime. this is my function:

const loadTemplate = async (readFile) => {
  try {
    let contents = await readFile({
      path: "./template.docx",
      directory: FilesystemDirectory.Data
      //encoding: FilesystemEncoding.UTF8
    });
    console.log(contents);
    return contents;
  } catch (e) {
    throw e;
  }
};

readFile function is destructed from useFilesystem() destructed from ‘@ionic/react-hooks/filesystem’.
it says Error: File does not exist.
How can I open binary file located in my project?

react-hooks installation is required.

npm install @ionic/react-hooks --save

Apologies if this is somehow different under React, but at least in an Angular project, you need to do this via HTTP, because everything in your app binary (including things in /assets) is really baked into the .apk or .ipa of your app. They aren’t accessible as filesystem objects, period.

1 Like