我正在研究与Rails API进行通信的Ionic应用程序。我有用户,用户有图片。我已经能够遵循this guide关于如何允许用户从他们的手机图像本地抓取图像。离子照片上传 - 文件到Base64字符串
这允许用户从他们的电话
$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编码的字符串。
我如何获得这个功能来运行,我从我的设备摄像头抓起文件后?
我能弄明白,回答以下
感谢答案。我几乎保留了所有的代码,但是用我的代码替换了我的'$ cordovaImagePicker.getPictures'(在我的编辑中)。我添加了一系列警报(用于测试“离子视图”)并获得完成文件名称的警报。但是,它并没有成为第二个'then'块。你有没有看到为什么会有这种情况? –
你安装了cordova-file插件吗? –
是的,我做到了。 [这是我安装的](https://github.com/apache/cordova-plugin-file) –