Skip to content

Attempting to access an external file on Android 10 causes FILE_NOT_FOUND_ERR #397

@AleFons

Description

@AleFons

Bug Report

Problem

What is expected to happen?

It should be able to access public files.

What does actually happen?

When attempting to access a file from outside the app's dataDirectory on Android 10, the plugin returns a FILE_NOT_FOUND_ERR.

Information

Android 10 comes with some changes in privacy that seem to be the cause; this problem specifically happens to me when I use the Camera plugin to select a picture from the photo roll and make a backup of it; when attempting to copy it to the app's directory, I get that error.

Command or Code

public async backupAnnexedFile(content_uri) {
    let link = content_uri;
    if (this.platform.is('android')) {
      link = await this.file_path.resolveNativePath(content_uri);
    }
    let old_path = link.slice(0, link.lastIndexOf('/') + 1);
    let old_filename = link.slice(link.lastIndexOf('/') + 1, link.length);
    let extension = old_filename.slice(old_filename.lastIndexOf('.'), old_filename.length);
    let new_path = 'path/to/file/';
    if (this.platform.is('cordova')) {
      new_path = this.fileHandler.dataDirectory.toString();
    }
    let new_filename = 'L_';
    new_filename = `${new_filename}${Date.now()}${extension}`;
    await this.fileHandler.copyFile(old_path, old_filename, new_path, new_filename).catch((error) => {
      console.log(error);
      throw error;
    });
    return `${new_path}${new_filename}`;
  }

Environment, Platform, Device

Android 10, has happened on multiple devices.

Version information

Ionic:

ionic (Ionic CLI) : 4.6.0
Ionic Framework : ionic-angular 3.9.6
@ionic/app-scripts : 3.2.4

Cordova:

cordova (Cordova CLI) : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0, ios 5.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.0.5, cordova-plugin-ionic-webview 2.2.0, (and 18 other plugins)

System:

Android SDK Tools : 26.1.1
NodeJS : v12.16.3
npm : 6.14.4
OS : Linux 4.15

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions