【发布时间】:2017-05-15 09:59:40
【问题描述】:
我正在开发一个与 Rails API 通信的 Ionic 应用程序。我有用户,用户有图片。我已经能够关注this guide,了解如何让用户从他们的手机图像中本地抓取图像。
这允许用户从他们的手机中抓取图像
$ionicPlatform.ready(function() {
$scope.getImageSaveContact = function() {
// Image picker will load images according to these settings
var options = {
maximumImagesCount: 1,
width: 800,
height: 800,
quality: 80
};
$cordovaImagePicker.getPictures(options).then(function (results) {
// Loop through acquired images
for (var i = 0; i < results.length; i++) {
$scope.collection.selectedImage = results[i]; // We loading only one image so we can use it like this
window.plugins.Base64.encodeFile($scope.collection.selectedImage, function(base64){ // Encode URI to Base64 needed for contacts plugin
$scope.collection.selectedImage = base64;
});
}
console.log("results");
console.log(results);
}, function(error) {
console.log('Error: ' + JSON.stringify(error));
});
};
});
问题是,它没有运行(或似乎没有运行)编码文件的window.plugins.Base64.encodeFile 行。现在,它只是图像文件,而不是 Base64 编码的字符串。
从我的设备摄像头抓取文件后,如何运行此功能?
我想通了,答案在下面
【问题讨论】: