FileReader API not firing
See original GitHub issueDescription of the problem: In my project I’m trying to read and convert a Blob downloaded from the dropbox api to a text string. When building my project using Cordova, the FileReader fires onload and onprogress events. When building using Capacitor, filereader does not fire any events at all.
Affected platform
- Android
- [x ] iOS
- electron
- web
OS of the development machine
- Windows
- [ x] macOS
- linux
Other information: As suggested in other bug reports, I tried wrapping the FileReader in
platform.ready().then(_ => {
/// perform file reading
})
and in
zone.run(() => {
/// perform file reading
})
None helped. Cordova has no issues reading the file.
When I use
var text = await (new Response(response.fileBlob)).text();
to read the file blob, it does work.
Capacitor version: 1.0.0-beta.24
Issue Analytics
- State:
- Created 4 years ago
- Comments:42 (6 by maintainers)
Top Results From Across the Web
FileReader onload function is not firing - Stack Overflow
This means that you are not dealing with the web-API's FileReader, but rather with some kind of a wrapper object.
Read more >FileReader: error event - Web APIs | MDN
The error event is fired when the read failed due to an error (for example, because the file was not found or not...
Read more >File readAsText not working - Capacitor - Ionic Forum
I tried to use the file-plugin like described here: https://ionicframework.com/docs/native/file Writing to a file seems to work.
Read more >File API - W3C
Publication as a Working Draft does not imply endorsement by W3C and its ... 6.1 The File Reading Task Source; 6.2 The FileReader...
Read more >FileReader onload not working in lightning component
You didn't actually read the file. You need to call one of readAsArrayBuffer, readAsBinaryString, readAsDataURL, or readAsText.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can try this.
If you have plugins that rely on FileReader working correctly, using snippets from the getFileReader() code mentioned above, I have a solution
Add to app.module.ts:
or add the above code to another file and import the file, not the class.
This is a hack but it means that when calling
new FileReader()
all the events work. Ideally it would be nice to be able to control the order in which scripts are imported. As the fix I’ve always used in a cordova based project is to change the order of polyfills.js and cordova.js in the index.html file.