I am using media plugin to record audio, i can record and play the audio. But I am having issues uploading it to firebase storage. Seems like I have to convert the file.mp3 to base64 first. any help??
1 Like
this is works for me:
saveRecord() {
console.dir(this.file.externalDataDirectory);
// save to firebase
// var file = {name:`${this.currentUid}.mp3`};
const fileName = {name: `${this.file.externalDataDirectory}/${this.currentUid}.mp3`};
const metadata = {
contentType: 'audio/mp3',
};
var blob = new Blob([fileName.name], {type: 'audio/mp3'}); // pass a useful mime type here
const uploadAudio = this.usersStorageAboutRecordRef.child(`${this.currentUid}/${fileName.name}`)
.put(blob, metadata);
// Listen for state changes, errors, and completion of the upload.
return uploadAudio.on(firebase.storage.TaskEvent.STATE_CHANGED, // or 'state_changed'
(snapshot) => {
}, (error) => {
console.dir(error);
}, () => {
// Upload completed successfully, now we can get the download URL
var downloadURL = uploadAudio.snapshot.downloadURL;
console.dir(downloadURL);
return new Promise((resolve, reject) => {
resolve(downloadURL);
});
});
}
1 Like