Hi community, I am recording an audio using MediaCapture and everything fine, that works perfect, then with the data of the file recorded and saved locally I am trying to save the recorded audio in Firebase Storage, I try to convert with the fullPath of the file in a blob to upload it but the conversion always returns empty or null I’ve also tried with file.readAsArrayBuffer but it always returns null, could someone tell me what I’m doing wrong?
I am using Ionic 5
recordAudio() {
const options: CaptureAudioOptions = { limit: 1, duration: 5 };
this.mediaC.captureAudio(options)
.then(async (data: MediaFile[]) => {
const metadata = {
contentType: 'audio/amr',
};
this.directory = data[0].fullPath;
const capturedAudio = data[0];
const localAudioPath = capturedAudio.fullPath;
const directoryPath = localAudioPath.substr(0, localAudioPath.lastIndexOf('/'));
const fileName = localAudioPath.substr(localAudioPath.lastIndexOf('/') + 1);
// const captureDataUrl = this.utils.dataURItoBlobAudio('data:audio/amr;base64,' + localAudioPath);
const audioBlob: any = new Blob([localAudioPath], { type: 'audio/amr' });
alert('audiBlob ' + JSON.stringify(audioBlob));
const storageRef = firebase.storage().ref();
const uploadAudio = storageRef.child(`files_audio/${fileName}`)
.put(audioBlob, metadata).then((sus) => {
sus.ref.getDownloadURL().then((url) => {
alert('url => ' + url);
}).catch((er) => {
this.utils.presentToastSimple('Error al obtener ruta del audio: ' + er, 5000);
});
}).catch((error) => {
alert('Error al guardar la imagen: ' + error);
});
// const fileBlob = new Blob([this.base64ToArrayBuffer(data[0].fullPath)], { type: 'audio/amr' });
}).catch((err: CaptureError) => {
alert('CaptureError: ' + JSON.stringify(err));
});
}
1 post - 1 participant