I am trying to upload photos to firebase storage using the cordova-plugin-camera with no success:
Here is my code:
let options:any = {
quality : 100,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : false,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
targetWidth: 1920,
targetHeight: 1920,
saveToPhotoAlbum: true,
cameraDirection: Camera.Direction.FRONT
};
Camera.getPicture(this.options).then( (imageData) => {
let blob: any = new Blob( [imageData], { type: "image/jpeg" } );
blob.name = 'image.jpg';
let storageRef: any = firebase.storage().ref();
let path: string = 'images/' + this.user.uid + '/' + Math.random().toString(36).substr(2, 9) + '.jpg';
console.log(path);
let uploadTask: any = storageRef.child(path).put(blob);
uploadTask.on('state_changed', function(snapshot) {
console.log(snapshot);
}, function(error) {
this.showAlert(error);
}, function() {
var downloadURL = uploadTask.snapshot.downloadURL;
console.log(downloadURL);
console.log(this.user);
this.user.set({photo: downloadURL});
});
}, (err) => {
this.showAlert(err);
});I don't know why but it seems that its uploading and when I check the file is empty.
Any help, please?
Thank you.
window.resolveLocalFileSystemURL(fileURI, function( fileEntry ){
fileEntry.file(function (resFile) {
var reader = new FileReader();
reader.onloadend = function(evt) {
var imgBlob = new Blob([evt.target.result], {type: 'image/jpeg'});
imgBlob.name = 'sample.jpg';
var uploadTask = FirebaseControls.storage('images/sample.jpg').put(imgBlob);
uploadTask.on('state_changed', function(snapshot){
console.log('state_changed');
}, function(error) {
console.log(JSON.stringify(error));
}, function() {
// Handle successful uploads on complete
// For instance, get the download URL: https://firebasestorage.googleapis.com/...
var downloadURL = uploadTask.snapshot.downloadURL;
});
};
reader.readAsArrayBuffer(resFile);
});
});