A JavaScript function for uploading a local file (using its URI) to Firebase storage.
The function requires jQuery.
Include the javascript file (minified).
The example usage is taking a picture and uploading it to Firebase
var storageRef = "path/to/firebase/storage";
var options = {
sourceType: Camera.PictureSourceType.CAMERA,
destinationType: Camera.DestinationType.FILE_URI
};
navigator.camera.getPicture(function(imageURI) {
cfUploadFile(storageRef, imageURI, "image/jpeg")
.then(function(snapshot) {
// upload success, handle returned snapshot (firebase.storage.UploadTaskSnapshot)
}).fail(function(err) {
// handle error
});
}, function(err) {
// cordova error
}, options);
The function cfUploadFile
takes 3 parameters (all string types). The first parameter will be your Firebase storage path, which is the location in which you would want to store the file. The second parameter will be the file URI. And lastly, the third parameter will be the file type.