I'm struggling to upload images into firebase storage from ngCordova camera plugin in a Ionic app.
I can't use the fileTransfert plugin cause there is no database url with firebase storage (unless I'm wrong...) and I can only store file.
Do you have some ideas on how to perform that?
Here is my code at the moment using cordova file to read and converting in blob:
$scope.fromLibrairy = function() {
$ionicPlatform.ready(function() {
var options = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
targetWidth: 300,
targetHeight: 300,
};
$cordovaCamera.getPicture(options).then(function(imageURI) {
$scope.imgURI = imageURI;
var name = imageURI.substring(imageURI.lastIndexOf('/')+1, imageURI.length);
var directory = imageURI.substring(0, imageURI.lastIndexOf('/')+1);
$cordovaFile.readAsArrayBuffer(directory, name).then(function(success) {
alert(success);
var blob = new Blob([success], { type:"image/jpeg" });
// Create the storage ref
var ref = storageRef.child('images/' + name);
// My function to upload in firebase storage (it works with jpeg)
$scope.uploadPhoto(blob, ref);
}, function (error) {
alert("erreur du readAsArrayBuffer" + error + error.code);
})
}, function(error){
alert('erreur du getPicture' + error);
});
});
};
Any help would be much appreciated! :)