I'm facing an error in my ionic android app. Using the exact same code as my ios app (ionic with two platforms : android and ios), i'm not able to send a base64 uri
to Firebase storage
.
The error is :
Uncaught TypeError: mountainImagesRef.putString is not a function
at navigator.camera.getPicture.quality (controllers.js:202)
at Object.callbackFromNative (cordova.js:294)
at <anonymous>:1:9
I saw something similar here, but the solution there was to update the plugin, and I'm already using the last version of cordova-plugin-camera
: V 4.0.3.
Uncaught TypeError: ref.putString is not a function
On my ios app, .putString()
function is working ! How can I make this work on my android app ? Do you see something I did wrong ? I've tried many ways to use putString
like uri.substring(0,23)
...etc.
function takePic()
{
navigator.camera.getPicture(
function(uri){
$ionicPopup.alert({
title: 'A new image',
template: 'Loading !'
});
// Create a root reference
var storageRef = firebase.storage().ref();
var filename = Math.floor((Math.random()*10000)+ 1);
var newAvatar_name = filename+".jpg";
var mountainImagesRef = storageRef.child("avatars/"+newAvatar_name);
mountainImagesRef.putString(uri, "base64").then(function(snapshot) {
console.log("Uploaded a base64 string!");
});
},
function(){
$ionicPopup.alert({
title: 'Error',
template: 'impossible to select one'
});
},
{
quality: 60,
targetHeight: 300,
targetWidth: 300,
destinationType: 0,
sourceType: 1,
mediaType: 0,
saveToPhotoAlbum: false
}
);
}