如何将galary图像发布到节点js

时间:2016-09-27 13:48:00

标签: javascript node.js cordova ionic-framework

我想将我的图库图片发布到nodeJs服务器我使用以下代码: -

  vm.getImageSaveContactInst = function() {       
  var options = {
      maximumImagesCount: 1, // Max number of selected images, I'm using only one for this example
      width: 800,
      height: 800,
      quality: 80            // Higher is better
  };
  $cordovaImagePicker.getPictures(options)
.then(function (results) {
  for (var i = 0; i < results.length; i++) {
    vm.imageInst = /*"data:image/jpeg;base64,"*/ + results[i];
    vm.imageFinalInst = "data:image/jpeg;base64," + vm.imageInst
  }
}, function(error) {
  // error getting photos
});
};

提前致谢:)

1 个答案:

答案 0 :(得分:0)

这个解决方案为我提供了最好的服务:

$ionicPlatform.ready(function () {
    var options1 = {
        maximumImagesCount: 1,
        width: 100,
        height: 100,
        quality: 50
    };
    $scope.takeFromGallery = function () {
        $cordovaImagePicker.getPictures(options1)
            .then(function (results) {
                window.resolveLocalFileSystemURL(results.toString(),
                    function (fileEntry) {
                        function win(file) {
                            var reader = new FileReader();
                            reader.onloadend = function (evt) {
                                $scope.registration.imgSrc = evt.target.result;    //this is your Base64 image  
                            };
                            reader.readAsDataURL(file);
                        };
                        var fail = function (evt) {};
                        fileEntry.file(win, fail);                           
                    },
                    function (error) {
                        console.log('error ' + error)
                    }
                );

            }, function (err) {
                console.log(err);
            });
    };
});

Source

P.S。:请不要忘记安装和注入Cordova File Plugin