I'm programming an application with ionic 1 and firebase 3.
I want to upload an image to the storage of firebase.
When I use html fileupload the image is saved but when i use "cordova.getPictures" the image is not saved.
The code:
.controller("PhotosCtrl",function($scope,$firebaseArray,$firebaseAuth,$firebaseObject, $timeout, $cordovaImagePicker, $ionicPopup){
$scope.upFile = function(){
pickTheImage().then(function(_image) {
processImage(_image);
})
}
function pickTheImage() {
var options = {
maximumImagesCount: 1,
width: 320,
quality: 80
};
return $cordovaImagePicker.getPictures(options).then(function (results) {
return results[0];
})
}
function processImage(_image) {
fetch(_image).then(function (_data) {
return _data.blob()
}).then(function (_blob) {
var task=firebase.storage().ref('images/12312355.jpg').put(_blob);
task.on('state_changed',
function progress(snapshot){
},
function error(err){
$ionicPopup.alert({
title: err
})
},
function complete(){
$ionicPopup.alert({
title: "Imagen guardada!"
})
}
);
})
}
})
Capturing image from camera will return the imageUrl. If you want to convert to blob type then using the below code in processImage function.
You can also refer http://ourcodeworld.com/articles/read/22/solve-native-path-of-android-content-if-resolvelocalfilesystemurl-doesn-t-work