I have tried to upload video to Firebase storage.
It’s work fine when upload image but I try to change to video and noting happening.
this line “alert(this.selected);” never alert. idk how to debug
anyone help please, I have stuck for week T T.
or if you guys have any good solutions please share thanks
getVideo() {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
mediaType: this.camera.MediaType.VIDEO,
}
this.camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
let base64Image = 'file:/' + imageData;
alert(base64Image);
alert(imageData);
this.selected = this.dataURItoBlob(base64Image);
alert(this.selected);
const id = Math.random().toString(36).substring(2);
this.ref = this.afStorage.ref(id);
this.task = this.ref.put(imageData);
console.log(imageData);
}, (err) => {
// Handle error
});
}
dataURItoBlob(dataURI) {
// code adapted from: http://stackoverflow.com/questions/33486352/cant-upload-image-to-aws-s3-from-ionic-camera
let binary = atob(dataURI.split(',')[1]);
let array = [];
for (let i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
return new Blob([new Uint8Array(dataURI)], {type: 'video/mp4'});
};