IONIC V1: save camera image to firebase storage
Budget: $10 – $75 CAD
We already have the following function which uploads image to our configured firebase storage (and it is tested to work):
uploadFile: function (imageFile) {
var storage = firebase.storage().ref(imageFile.name);
var upload = storage.put(imageFile);
upload.on(
function error() {
alert("error uploading file");
},
function complete() {
alert("upload complete");
}
);
},
Then, we have the following cordova camera plugin function, which takes pictures successfully
$scope.takePicture = function () {
var options = {
quality : 75,
targetWidth: 200,
targetHeight: 200,
sourceType: 1
};
Camera.getPicture(options).then(function(imageData) {
//XXXXXXXX
}, function(err) {
console.log(err);
});
};
We want to fill the //XXXXXX in the above, with a function that converts the camera output imageData, into something that the function uploadFile() can read and upload to firebase storage. We don't want to inject or install any new library or plugin. We just want it to be done with js as is. The second, task, is we want the uploadFile() to return the public URL where the image was stored on the firebase storage, so we can access it later.
uploadFile: function (imageFile) {
var storage = firebase.storage().ref(imageFile.name);
var upload = storage.put(imageFile);
upload.on(
function error() {
alert("error uploading file");
},
function complete() {
alert("upload complete");
}
);
},
Then, we have the following cordova camera plugin function, which takes pictures successfully
$scope.takePicture = function () {
var options = {
quality : 75,
targetWidth: 200,
targetHeight: 200,
sourceType: 1
};
Camera.getPicture(options).then(function(imageData) {
//XXXXXXXX
}, function(err) {
console.log(err);
});
};
We want to fill the //XXXXXX in the above, with a function that converts the camera output imageData, into something that the function uploadFile() can read and upload to firebase storage. We don't want to inject or install any new library or plugin. We just want it to be done with js as is. The second, task, is we want the uploadFile() to return the public URL where the image was stored on the firebase storage, so we can access it later.