Convert ionic native mediaobject audio to blob


#1

Hay folks. I need some really quick solution. I hope you can help me solve this.

I am using ionic native media object : https://ionicframework.com/docs/native/media/
I record sound on android or ios, then i want to upload it to node.js server. The thing is node.js server must get base64 encoded audio. so I have to get base64 of audio in ionic. I don’t know how to do that. I tried to use plugin : https://ionicframework.com/docs/native/base64/ but it’s in beta , not a good one also because many people say doesn’t work for ios. so I tried Javascript FileReader.

var reader = new FileReader();
reader.readAsDataURL(blob);

// but there it only accepts blob, not a filepath or audiomedia object. so I figured I have to transfer my audio to blob.

I tried

1) var blob = new Blob([this.audio], {type:‘audio/mp3’});
2) var blob = new Blob([this.filePath], {type:‘audio/mp3’});
and than reader.readAsDataURL(blob).

Thing is it gives me base64 encoded, but it’s so little length. i send it to server but in server it doesn’t play.
I guess it goes in a bad base64 form from ionic. (because it’s too little) . on pc i am using react , i send base64 and it’s too big . that’s why i think i am making a terrible mistake. could you point me out to the right direction?

Thanks