apache / apache/cordova-plugin-file
FileReader.readAs*(file) returns null onloadend
- Dominant language
- JavaScript
- Stars
- 744
- Forks
- 754
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 1
Description
# Bug Report
FileReader.readAs*(file) returns null in **this.result** and has FileError with code: 1 (not found) with video file.
## Problem
The exact same code works fine on iOS, however I can't get it to work on Android.
## Information
The command below will make it easier to understand what I'm trying to do.
### Code
This is already set
```
```
Actual code
```
async captureVideoErrorOnAndroid() {
const printError = (e) => console.log(e);
navigator.device.capture.captureVideo(function(mediaFiles) {
const mediaFile = mediaFiles[0];
console.log(`capture: Got media file: ${JSON.stringify(mediaFile)}`);
// note, on iOS I have to use media.localURL rather than media.fullPath
// I also tried media.localURL on Android, but the results are the same
window.resolveLocalFileSystemURL(mediaFile.fullPath, function(fileEntry){
console.log(`capture: Got fileEntry: ${JSON.stringify(fileEntry)}`);
fileEntry.file(function (file) {
console.log(`capture: Got file: ${JSON.stringify(file)} `);
const reader = new FileReader();
reader.onloadend = function() {
console.log(`capture: result: ${this.result}, error: ${JSON.stringify(this.error)}`);
};
reader.readAsArrayBuffer(file);
}, printError);
}, printError)
}, printError, {limit: 1, quality: 0, duration: 10})
}
```
### Output for iOS (working just fine)
```
capture: Got media file: {"name":"58568874201__E85C0792-08F4-4652-9776-9E0815101786.MOV","localURL":"cdvfile://localhost/temporary/58568874201__E85C0792-08F4-4652-9776-9E0815101786.MOV","type":"video/quicktime","lastModified":null,"lastModifiedDate":1563995943708.5723,"size":87457,"start":0,"end":0,"fullPath":"/private/var/mobile/Containers/Data/Application/B8A6D1DC-72B7-4F8C-A106-A137E358E0AA/tmp/58568874201__E85C0792-08F4-4652-9776-9E0815101786.MOV"} (cordova.js, line 1732)
capture: Got fileEntry: {"isFile":true,"isDirectory":false,"name":"58568874201__E85C0792-08F4-4652-9776-9E0815101786.MOV","fullPath":"/58568874201__E85C0792-08F4-4652-9776-9E0815101786.MOV","filesystem":"","nativeURL":"file:///var/mobile/Containers/Data/Application/B8A6D1DC-72B7-4F8C-A106-A137E358E0AA/tmp/58568874201__E85C0792-08F4-4652-9776-9E0815101786.MOV"} (cordova.js, line 1732)
capture: Got file: {"name":"58568874201__E85C0792-08F4-4652-9776-9E0815101786.MOV","localURL":"cdvfile://localhost/temporary/58568874201__E85C0792-08F4-4652-9776-9E0815101786.MOV","type":"video/quicktime","lastModified":1563995943708.5723,"lastModifiedDate":1563995943708.5723,"size":87457,"start":0,"end":87457} (cordova.js, line 1732)
capture: result: [object ArrayBuffer], error: null (cordova.js, line 1732)
```
### Output for Android (with result being null)
```
capture: Got media file: {"name":"VID_20190725_030555.3gp","localURL":"cdvfile://localhost/sdcard/DCIM/Camera/VID_20190725_030555.3gp","type":"video/3gpp","lastModified":null,"lastModifiedDate":1563995159000,"size":75157,"start":0,"end":0,"fullPath":"file:///storage/emulated/0/DCIM/Camera/VID_20190725_030555.3gp"}
capture: Got fileEntry: {"isFile":true,"isDirectory":false,"name":"VID_20190725_030555.3gp","fullPath":"/DCIM/Camera/VID_20190725_030555.3gp","filesystem":"","nativeURL":"file:///storage/emulated/0/DCIM/Camera/VID_20190725_030555.3gp"}
capture: Got file: {"name":"VID_20190725_030555.3gp","localURL":"cdvfile://localhost/sdcard/DCIM/Camera/VID_20190725_030555.3gp","type":"video/3gpp","lastModified":1563995159000,"lastModifiedDate":1563995159000,"size":75157,"start":0,"end":75157}
capture: result: null, error: {"code":1}
```
### Platform
Android 8.0.0
### Version information
Cordova 8.1.2
cordova-plugin-file 6.0.2
## Checklist
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
Contributor guide
Research direction
Reproduce the Android 8.0 case using navigator.device.capture.captureVideo, resolveLocalFileSystemURL, and FileReader.readAsArrayBuffer with the reported Cordova and file-plugin versions. Compare the Android and iOS outputs, then trace the Android handling of the returned video file. Done means onloadend provides the expected ArrayBuffer without FileError code 1 for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, javascript
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100