cordova-plugin-file icon indicating copy to clipboard operation
cordova-plugin-file copied to clipboard

FileReader.onloadend event of the plugin Cordova-plugin-file is not getting triggered for Android device

Open KoushikMahadikar opened this issue 3 years ago • 3 comments
trafficstars

Bug Report

Problem

FileReader.onloadend event of the plugin Cordova-plugin-file is not getting triggered for Android device

What is expected to happen?

FileReader.onloadend event of the plugin cordova-plugin-file should be triggered for Android device

What does actually happen?

We are using Cordova plugin cordova-plugin-file to read a file in one of the mobile app. But, FileReader.onloadend event of this plugin is not getting triggered for Android. This issue is replicable in Android 10

Information

We are using Cordova plugin -cordova-plugin-file to read a file in one of the mobile app. But, FileReader.onloadend event of this plugin is not getting triggered for Android. This issue is replicable in Android 10

Command or Code

const reader = new FileReader(); reader.onloadend = (evt: any) => { imgBlob = new Blob([evt.target.result], { type: 'image/jpeg' }); resolve(imgBlob); };

Environment, Platform, Device

We are experiencing this issue in Android device which is having Android 10

Version information

cordova-plugin-file version - 6.0.2 cordova-android version - 9.1.0

Checklist

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

KoushikMahadikar avatar Nov 15 '22 03:11 KoushikMahadikar

I'm seeing similar issues for some Cordova projects. It occurs for me with [email protected], and [email protected]. I'll update with any additional context if I can find it.

mattdsteele avatar Feb 09 '23 21:02 mattdsteele

@KoushikMahadikar are you working in an Angular project?

We discovered a similar issue in Capacitor's file loader. It appears to be a bug in zone.js that causes the onloadend method not to make it into the FileReader class. https://github.com/ionic-team/capacitor/issues/1564

This workaround worked for me:

export function getFileReader(): FileReader {
    const fileReader = new FileReader();
    const zoneOriginalInstance = (fileReader as any)["__zone_symbol__originalInstance"];
    return zoneOriginalInstance || fileReader;
}
...
let newInstance = getFileReader();

mattdsteele avatar Feb 09 '23 22:02 mattdsteele