FileReader events not firing in iOS


#1

So I am looking to upload video files on ios. I read in a file using the fileEntry.file(*) method that results in a file entry that looks like this.

{"name":"trim.EFD002FA-9AAD-458C-943E-3F023677409E.MOV","localURL":"cdvfile://localhost/temporary/trim.EFD002FA-9AAD-458C-943E-3F023677409E.MOV","type":null,"lastModified":1476913187000,"lastModifiedDate":1476913187000,"size":2401699,"start":0,"end":2401699}

Then I use the below code.

             fileEntry.file( (file) => {
           console.log('File: ' + (typeof file) + ', ' + JSON.stringify(file));
           const fileReader = new FileReader();

           if (file.type === null) {
             file.type = 'video/mov';
           }
           
           fileReader.onloadend = (result: any) => {
             console.log('File Reader Result: ' + JSON.stringify(result));
             // Create Thumbnail
             let arrayBuffer = result.target.result;
             this.createThumbnail(arrayBuffer);
             let blob = new Blob([new Uint8Array(arrayBuffer)], {type: file.type});
             const name = '' + Date.now() + this.auth.id;
             this.upload(blob, name , file.type, resolve, reject);
           };

           fileReader.onloadstart = (message) => {
             console.log('On Load Start' , message);
           };

           fileReader.onprogress = (progress) => {
             console.log('File Reader Progress: ' , progress);
           };

           fileReader.onerror = (error: any) => {
             console.log('FileReader Error' + JSON.stringify(error));
             reject(error);
           };

           fileReader.onabort = (abort) => {
             console.log('File Reader aborted: ' , abort);
             reject(abort);
           };

           fileReader.onload = () => {
             console.log('onload');

            };
           
           console.log('FileReader reading: ' , fileReader);
           fileReader.readAsArrayBuffer(file);
           
         }, (error) => {
           console.log('File Entry Error: ' + JSON.stringify(error));
           reject(error);
         });

The code above works on android. But on ios nothing happens at all. None of the lifecycle events for filereader are called, and there is no error thrown.

I am running ionic RC.1


#2

Replying to my own comment. There is a workaround at the moment for this referenced in this github issue with ionic-native

The issue is still open.