无法将图片的网址上传到firebase存储空间

时间:2016-09-13 02:10:01

标签: angularjs ionic-framework firebase

我是新的离子,该程序完美地拍摄照片并发送到firebase。我的问题是:如何在视图中显示图像的URL?我有这个控制器:

如果我能提供帮助,我很感激,问候



.controller("formCtrl", function($scope,sharedUtils,$ionicPopup,$state, $rootScope, $cordovaCamera)
{

$scope.capturarFoto = function(sourceType) {

 var options = {
        quality : 75,
        destinationType : Camera.DestinationType.FILE_URI,
        sourceType : sourceType,
        encodingType: Camera.EncodingType.JPEG,
        popoverOptions: CameraPopoverOptions,
        targetWidth: 500,
        targetHeight: 500,
        saveToPhotoAlbum: false
    };
  
    $cordovaCamera.getPicture(options).then(function(imageData) {

 // $scope.images = imageData;

 var storageRef = firebase.storage().ref();
 // filename = imageData.name;

var getFileBlob = function(url, cb) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", url);
    xhr.responseType = "blob";
    xhr.addEventListener('load', function() {
        cb(xhr.response);
    });
    xhr.send();
};

var blobToFile = function(blob, name) {
    blob.lastModifiedDate = new Date();
    blob.name = name;
    return blob;
};

var getFileObject = function(filePathOrUrl, cb) {
    getFileBlob(filePathOrUrl, function(blob) {
        cb(blobToFile(blob, new Date().getTime()));  // segundo parametro es el nombre de imagen
    });
};

 

  getFileObject(imageData, function(fileObject) {

    var metadata = {
    'contentType': fileObject.type
  };
    storageRef.child('images/' + fileObject.name).put(fileObject, metadata);

    uploadTask.on('state_changed', null, function(error) {
    // [START onfailure]
    console.error('Upload failed:', error);
    alert('Upload failed:', error);
    // [END onfailure]
  }, function() {
    console.log('Uploaded',uploadTask.snapshot.totalBytes,'bytes.');
    console.log(uploadTask.snapshot.metadata);
    var url = uploadTask.snapshot.metadata.downloadURLs[0];
    console.log('File available at', url);
    // [START_EXCLUDE]
    document.getElementById('linkbox').innerHTML = '<img src="' +  url + '">';
    // [END_EXCLUDE]
  });

});
    }, function(error) {
        console.error(error);
        alert(error);
    });


};
&#13;
<ion-view style="" class=" " id="page8" title="Enviar Incidencia">
    <ion-content class="has-header" padding="true" ng-controller="formCtrl">
 
 <button class="button button-full button-assertive" ng-click="capturarFoto()">
           take Photo
</button>
   
</ion-content>
</ion-view>
&#13;
&#13;
&#13;

修复并为我工作:

之前:uploadTask.on(&#39; state_changed&#39;,null,function(error){ 之后:var uploadTask = uploadTask.on(&#39; state_changed&#39;,null,function(error){

:)

0 个答案:

没有答案
相关问题