Ionic Native File - Where does it store the files in iOS?

Hi

I been trying to save a file on iOS. Right now I been running through Xcode right to my phone.

When I run the app it says that is saved successfully. But I don’t see any file when I use a file manager app like FileApp, FileManager, iCloud and the Apple crappy Files app.

My question is that I heard from a web search that in order to save the file iOS creates a sandbox folder for the app.

If I been saving it to this.file.documentDirectory, how can a user open it in let’s say Pages or Numbers apps? (You know Apple’s Word and Excel replacement for the uninitiated.)

Here’s the code.

  writeToIOS(opts : {
    fileName: string,
    text: any
  }) : Promise < IResponse < any >> {
    let response: IResponse < boolean > = {
      success: false,
      error: '',
      data: false
    };
    const options: IWriteOptions = {
      replace: true
    };
    return new Promise((resolve, reject) => {
      const path = this.file.documentsDirectory;
      const directory = 'Attendance Log';
      this
        .file
        .checkDir(path, directory)
        .then(res => {
          this
            .file
            .writeFile(path + directory, opts.fileName, opts.text, options)
            .then(res => {
              response = {
                ...response,
                success: true,
                error: res,
                data: res
              };
              resolve(response);
            })
            .catch(error => reject(error));
        })
        .catch(() => {
          this
            .file
            .createDir(path, directory, true)
            .then(directory => {
              this
                .file
                .writeFile(path + directory.name, opts.fileName, opts.text, options)
                .then(res => {
                  response = {
                    ...response,
                    success: true,
                    error: res,
                    data: res
                  };
                  resolve(response);
                })
                .catch(error => reject(error));
            })
            .catch(error => reject(error));
        });
    });
  }

Bumping because it’s daytime now lol. Really need some feedback on this :confused:

@Sujan12 can you help me on this?

Did you find a solution on this?

Yes, I use a ionic native plugin called fileopener and basically gave the user the choice of where to save the exported file.

for future visitors, I think this is the code Bandito proposed:
source

const options = {
  replace: true
};
const path = this.file.documentsDirectory;
const directory = 'Attendance Log';
this.file
   .checkDir(path, directory)
      .then(res => {
   this.file
      .writeFile(path + directory, opts.fileName, opts.text, options)
         .then(res => {
   this.fileOpener
      .open(`${path}${directory}/${opts.fileName}` , 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
      .then(() => ...)
      .catch(error => ...);
})
.catch(error => ...);