【问题标题】:Ionic 1, firebase storage, cordova.getPictures, not save images?Ionic 1,firebase 存储,cordova.getPictures,不保存图片?
【发布时间】:2017-02-22 13:58:56
【问题描述】:

我正在编写应用程序 使用 ionic 1 和 firebase 3。

我想上传一张图片到 firebase 的存储中。

当我使用 html 文件上传时,图像被保存,但是当我使用“cordova.getPictures”时,图像没有被保存。

代码:

.controller("PhotosCtrl",function($scope,$firebaseArray,$firebaseAuth,$firebaseObject, $timeout, $cordovaImagePicker, $ionicPopup){

 $scope.upFile = function(){

    pickTheImage().then(function(_image) {
    processImage(_image);

    })

 }

 function pickTheImage() {
      var options = {
        maximumImagesCount: 1,
        width: 320,
        quality: 80
      };

      return $cordovaImagePicker.getPictures(options).then(function (results) {
           return results[0];
        })
    }

  function processImage(_image) {

     fetch(_image).then(function (_data) {
        return _data.blob()
      }).then(function (_blob) {

        var task=firebase.storage().ref('images/12312355.jpg').put(_blob);

        task.on('state_changed', 

        function progress(snapshot){
        },
        function error(err){
            $ionicPopup.alert({
            title: err
          })
        },
        function complete(){
            $ionicPopup.alert({
              title: "Imagen guardada!"
            })
        }
    );
      })
  }
})

【问题讨论】:

    标签: angularjs ionic-framework cordova-plugins firebase-storage getpicture


    【解决方案1】:

    从相机捕获图像将返回 imageUrl。如果要转换为 blob 类型,请在 processImage 函数中使用以下代码。

    //Read the file entry from the file URL
                resolveLocalFileSystemURL(imgUrl, function (fileEntry) {
                    fileEntry.file(function (file) {
                        var reader = new FileReader();
                        reader.onloadend = function () {
                            var imgBlob = new Blob([this.result], {
                                    type: file.type
                                });
                            var imgFile = imgBlob;
    
                        };
                        reader.readAsArrayBuffer(file);
                    });
                }, function () {
                    //on Error
                });
    

    你也可以参考 http://ourcodeworld.com/articles/read/22/solve-native-path-of-android-content-if-resolvelocalfilesystemurl-doesn-t-work

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-05
      • 1970-01-01
      • 2021-11-20
      • 1970-01-01
      • 2017-05-25
      • 2020-12-30
      • 1970-01-01
      • 2020-12-25
      相关资源
      最近更新 更多