DirectoryEntry.getFile() failing when getting a file with a filename containing spaces

ionic native version:
ionic-native/file : “5.23.0”

DirectoryEntry.getFile() failing with error code 1, which is i am assuming, ERR_NOT_FOUND. when getting file with filename that contains space. getFile() function works properly if the filename does not contain any spaces.

here is my function, I also confirm if the filepath exists via the DirectoryEntry.createReader() and use the readEntries() function.

  accessFileEntry(
    directory: DirectoryEntry,
    filePath: string | string[],
    options?: Flags
  ): Observable<FileEntry> {
    if (Array.isArray(filePath) && filePath.length <= 0) { return EMPTY; }

    return wrapWithObservable(callbacks => {
      Sulat.verbose('Attempting to access file entry.');

      if (Array.isArray(filePath)) {
        if (filePath.length <= 0) {
          Sulat.error(
            'Failed to access file entry because the given filePath was an empty string array.'
          );
          callbacks.error(new EmptyError());
          return;
        }
        Sulat.warn(
          'For some reason, a string array was given to the app. Retrieving the first file path value of ' +
            filePath.length +
            ' entries.'
        );
        filePath = filePath[0];
      }

      Sulat.verbose('Searching in: ' + directory.toURL());
      Sulat.verbose('Relative path: ' + filePath);
      Sulat.verbose('Typeof filepath' + typeof filePath);
      Sulat.dir(filePath);

      const successGetFile = (fileEntry: FileEntry) => {
        Sulat.verbose('Successfully found fileEntry: ' + fileEntry.toURL());
        callbacks.success(fileEntry);
      };

      const failedGetFile = (error: FileError) => {
        Sulat.debug(`File system is at: ${directory.toURL()}`);
        console.log(`File system is at: ${directory.toURL()}`);
        console.log(`error at:: ${JSON.stringify(error)}`);

        callbacks.error(
          new ResourceError(
            `Failed to get FileEntry for ${filePath}`,
            `mapFilePathToFileEntry - FileEntry`,
            error
          )
        );
      };
      const success = function(entries){
          var i;
          console.log('check file if exists in directory, success :');
          for (i=0; i<entries.length; i++) {
              if(filePath ==  encodeURI(entries[i].name)){
                console.log(filePath + " === " + encodeURI(entries[i].name) + " : " + (filePath == encodeURI(entries[i].name)));
                filePath = entries[i].name;
              }
          }
          
      }
      const fail = function(entries){
          console.log('check file if exists in directory, failed :');
      }
      var directoryReader =  directory.createReader();
      directoryReader.readEntries(success,fail);  

      console.log('FILEPATH:: DECODED', Array.isArray(filePath)?filePath:decodeURI(filePath));
      directory.getFile((filePath), options, successGetFile, failedGetFile);
    });
  }

and the output is

[ng] [console.log]: "imagefilepath: " "file:///data/user/0/com.bpi.bpiloans.uat/cache/tmp_File%20name317620520127788763.png"
[ng] [console.log]: "FILEPATH:: DECODED" "tmp_File name317620520127788763.png"

[ng] [console.log]: "check file if exists in directory, success :"
[ng] [console.log]: "tmp_File%20name317620520127788763.png === tmp_File%20name317620520127788763.png : true"

[ng] [console.log]: "File system is at: file:///data/user/0/com.bpi.bpiloans.uat/cache/"
[ng] [console.log]: "error at:: {\"code\":1}"
[ng] [console.log]: "CAUGHTERRROR HERE " {
[ng]   "scope": "mapFilePathToFileEntry - FileEntry",
[ng]   "parentError": {
[ng]     "code": 1
[ng]   }
[ng] }

I got it working, I forgot I was already getting the FileEntry of the file when I reiterate on the readEntries(success,fail) function.

So I just manually find the file using the filename then use that FileEntry Object when the DirectoryEntry.getFile() function fails.

So, for anyone having problems with the DirectoryEntry.getFile() function, you can just create a DirectoryEntry.createReader(); Object then reiterate over its .readEntries() function

const failedGetFile = (error: FileError) => {
        Sulat.debug(`File system is at: ${directory.toURL()}`);
        console.log(`File system is at: ${directory.toURL()}`);
        console.log(`error at:: ${JSON.stringify(error)}`);
        var directoryReader =  directory.createReader();
        directoryReader.readEntries(successRead,failRead);  
        // callbacks.error(
        //   new ResourceError(
        //     `Failed to get FileEntry for ${filePath}`,
        //     `mapFilePathToFileEntry - FileEntry`,
        //     error
        //   )
        // );
      };
      const successRead = function(entries: FileEntry[]){
          var i;
          console.log('check file if exists in directory, success :');
          for (i=0; i<entries.length; i++) {
              if(filePath ==  encodeURI(entries[i].name)){
                console.log(filePath + " === " + encodeURI(entries[i].name) + " : " + (filePath == encodeURI(entries[i].name)));
                console.log('FOUND FILE ENTRYY',entries[i]);
                callbacks.success(entries[i]); break;
                // filePath = entries[i].name;
              }
          }
          
      }