Ionic 3 FireReader not working but Ionic 4 can

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I built my Ionic project on two different computers and got different result.

The first computer: Ionic Info

Ionic:

ionic (Ionic CLI) : 4.2.1 (/usr/local/lib/node_modules/ionic) Ionic Framework : ionic-angular 3.9.2 @ionic/app-scripts : 3.2.0

Cordova:

cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1) Cordova Platforms : android 7.1.1 Cordova Plugins : no whitelisted plugins (19 plugins total)

System:

NodeJS : v8.11.3 (/usr/bin/node) npm : 6.2.0 OS : Linux 4.15

FileReader only work when I put await in reader.readAsDataURL();

The second computer:

Ionic info

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 8.0.0

local packages:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : ios 4.5.4
Ionic Framework    : ionic-angular 3.9.2

my code:

async downloadFromURL(fileName, mimeType, url){
    return new Promise((resolve,reject) => {
        try{
            var self = this;
            var xhr = new XMLHttpRequest();
            xhr.open('GET', url, true);
            xhr.responseType='blob';  
            xhr.onloadend = async function(e) {
                if (xhr.status == 200)
                {
                    var reader = new FileReader();
                    reader.onloadend = async function(event){
                        var response = self.insertFile({
                            'type': mimeType,
                            'title': fileName
                        }, event.target["result"].split(',')[1]);
                        resolve(response);
                    }
                    await reader.readAsDataURL(xhr.response);
                }
            };
            xhr.send();
        } catch (error) {
            reject();
            console.log("error", error);
        }
    });
}

So, my question is how can I fix this without update ionic and cordova?

And sorry for my bad english :D

Thanks in advance.

profilepic.png
manpreet 2 years ago

in your index.html try moving the script tag for cordova.js from the header to the body, below the build/polyfills.js script tag. My body tag now looks like this:

<body>

  
  

  
  

  
  

  
  

  
  

body>

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.