我想将我的图库图片发布到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
});
};
提前致谢:)
答案 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);
});
};
});
P.S。:请不要忘记安装和注入Cordova File Plugin