Upload Camera Images To Firebase Using Ionic Framework

that did the trick. Thanks very much:slight_smile:

Hello Bengtler looked around nothing on uploading screenshots to firebase using import {Screenshot} from ‘ionic-native’;. Any information on this

Hey Aaron,
I tried your code but $cordovaFile.readAsArrayBuffer returns an error. So I tried to log cordova.file.cacheDirectory but it returns null and also cordova.file returns null.
I reinstalled the plugin and built the android but it is also gives an error. Can you help please ?!

did you install the file manager plugin? without seeing error logs or code, not much i can do - also are you on Ionic1 or Ionic2?

Yes, I installed the cordova-plugin-file couple of times and it is still not working. I am using Ionic 1

Updated code:

ionic.Platform.ready(function(){
$cordovaImagePicker.getPictures(options)
.then(function (results) {
console.log('Image URI: ’ + results[0]);
$scope.profilePicture = results[0];
alert(results[0]);
// lets read the image into an array buffer…
// see documentation:
// http://ngcordova.com/docs/plugins/file/
fileName = results[0].replace(/^.*[\/]/, ‘’);
alert(fileName);
// modify the image path when on Android
if ($ionicPlatform.is(“android”)) {
path = cordova.file.cacheDirectory
} else {
path = cordova.file.tempDirectory
}
alert(JSON.stringify(cordova.file.cacheDirectory));
var filePath = cordova.file.cacheDirectory +"/" +fileName;
alert(filePath);
$cordovaFile.readAsArrayBuffer(path, fileName)
.then(function(succcess){
alert(“success”)
var imageBlob = new Blob([success], { type: “image/jpeg” });
var storage = userAuth.getStorage();
var saveRef = storage.ref(‘images’).child(fileName);
var uploadTask = saveRef.put(imageBlob);
uploadTask.on(‘state_changed’, function(snapshot){

         }, function(error){
           alert("Database error: " + error);
         }, function(){
           var downloadURL = uploadTask.snapshot.downloadURL;
           alert(downloadURL);
         });

    }).catch(function(error){
      alert("File Error: " + error.code);
    });

}, function (error) {
// error
alert("Image Picker error: " + error)
});

});

Returns Cordova File error: Undefined