How can upload an audio file to FireBase?

Hi,

I want to upload recorded audio to FireBase storage, but even though I have not worked for a long time, I still working for this.

I seemed to have three options; upload with API, upload with FireBase, upload with socket.

I tried the first two options, but I did not get a nice result.

Finally, I tried the second option. I’ve successfully sent the audio file to FireBase. But the file looks bad, It can’t play.

Here is the my code for this;

DataProvider.ts:

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { AngularFireStorage, AngularFireUploadTask } from 'angularfire2/storage';
import { DateTime } from 'ionic-angular';

@Injectable()
export class DataProvider {

  constructor(private db: AngularFireDatabase, private storage: AngularFireStorage) {

  }

  uploadToStorage(blob, metadata): AngularFireUploadTask {
    let newName = new Date().getTime() + '.mp3';

    return this.storage.ref('files/' + newName).put(blob);
  }

}

Post.ts

doPost() {
    const metadata = {
      contentType: 'audio/mp3',
    };
    const file = { dir: this.navParams.get('fileDir') }
    console.log('Dir:' + file.dir);
    var blob = new Blob([file.dir], { type: 'audio/mp3' });

    let upload = this.dataProvider.uploadToStorage(blob, metadata);

    upload.then().then(res => {
      console.log('res: ', res);
    })
  }