将离子图像上传到Firebase存储

将离子图像上传到Firebase存储

本文介绍了将离子图像上传到Firebase存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am trying to upload an image from my image gallery into my firebase storage folder with ionic. This works fine for ios emulator but does not work on android. What might be the problem ? What should I check ?

//这是默认选项
$ scope.capturarFoto = function(type){
var opcionesCaptura = {
destinationType:Camera.DestinationType.FILE_URI,
sourceType:Camera.PictureSourceType [type.toUpperCase()],
};

// this is the default options $scope.capturarFoto = function (type) { var opcionesCaptura = { destinationType: Camera.DestinationType.FILE_URI, sourceType: Camera.PictureSourceType[type.toUpperCase()], };

    $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);


推荐答案

我也是Cordova的新手,但我相信您需要相机功能才能确保您的设备准备就绪:

I am also new to Cordova but I believe for Camera functionality you would need to ensure that your device is ready:

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

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

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

}

我确定这是你必须采取的方法。试试看,看看它是否有效。

I'm sure this is the approach you'd have to take. Try that and see if it works.

这篇关于将离子图像上传到Firebase存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 14:09