我正在研究與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) –