2016-09-27 65 views
0

我要發佈我的畫廊圖像服務器的NodeJS我用下面的代碼: -如何發佈galary圖像節點JS

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

提前:)謝謝

+0

然後是什麼問題?你有沒有在node.js中定義任何路徑來獲取它? – abdulbarik

+0

我應該向節點服務器發送vm.imageFinalInst值嗎? –

回答

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

PS:請不要忘記安裝並注入Cordova File Plugin

+0

它崩潰我的畫廊:( –

+0

但它不應該你做錯了什麼,我已經編輯了這篇文章,並提供了我的完整代碼給你以上 –

+0

仍然沒有工作:( –