2016-08-05 38 views
0

// Das ist die Standardoptionen $ scope.capturarFoto = function (Typ) {var opcionesCaptura = { Zieltyp: Camera.DestinationType.FILE_URI, source: Camera.PictureSourceType [type.toUpperCase()], };Ionic Hochladen von Bildern in Firebase Speicher

$cordovaCamera.getPicture(opcionesCaptura) 
     .then(procesarImagen, procesarError); 
}; 

function procesarImagen(pathImagen) { 
    var directorioFuente = pathImagen.substring(0, pathImagen.lastIndexOf('/') + 1), 
     archivoFuente = pathImagen.substring(pathImagen.lastIndexOf('/') + 1, pathImagen.length), 
     nombreParaGuardar = new Date().valueOf() + archivoFuente; 

    $cordovaFile.readAsArrayBuffer(directorioFuente, archivoFuente) 
     .then(function (success) { 
      var blob = new Blob([success], {type: 'image/jpeg'}); 
      enviarFirebase(blob, nombreParaGuardar); 
     }, function (error) { 
      console.error(error); 
     }); 
} 


function enviarFirebase(file, nombre) { 
    var storageRef = firebase.storage().ref(); 
    var uploadTask = storageRef.child('images/' + nombre).put(file); 
    uploadTask.on('state_changed', function (snapshot) { 
     console.info(snapshot); 
    }, function (error) { 
     console.error(error); 
    }, function() { 
     var downloadURL = uploadTask.snapshot.downloadURL; 
     console.log(downloadURL); 

Antwort

0

Ich bin auch neu in Cordova, aber ich glaube, dass Sie für die Kamerafunktionen müssten, um sicherzustellen, dass das Gerät bereit ist:

document.addEventListener("deviceready", onDeviceReady, false); 

function onDeviceReady() { 
    console.log(navigator.camera); 

    /* Here you can have $scope.choosePhoto = ... */ 

} 

Ich bin sicher, dies ist der Ansatz Sie haben würde nehmen. Probieren Sie es aus und sehen Sie, ob es funktioniert.

+0

Vielen Dank Zain, ich fand meine Antwort hier: http://StackOverflow.com/Questions/37452489/Upploading-Bild-to-firebase-Speicher-von-Cordova-App – burc

+0

Dieses Beispiel, dass ich Ihnen als Link gesendet funktioniert nur mit ios, funktioniert aber nicht mit android. Was könnte das Problem sein? – burc