0

ionic 1 と firebase 3 でアプリケーションをプログラミングしています。

firebaseのストレージに画像をアップロードしたいです。

html fileupload を使用すると画像は保存されますが、「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!"
            })
        }
    );
      })
  }
})
4

1 に答える 1

0

カメラから画像をキャプチャすると、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も参照できます

于 2016-10-13T15:51:41.867 に答える