{"size": 1164, "ext": "js", "max_stars_repo_path": "d4d-web/public/components/imageuploading/imageUpload.js", "max_stars_repo_name": "prashant0598/D4D---Drone-4-Dengue", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "d4d-web/public/components/imageuploading/imageUpload.js", "max_issues_repo_name": "prashant0598/D4D---Drone-4-Dengue", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "d4d-web/public/components/imageuploading/imageUpload.js", "max_forks_repo_name": "prashant0598/D4D---Drone-4-Dengue", "max_forks_repo_forks_event_min_datetime": "2019-07-02T08:30:47.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-02T08:30:47.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 27.7142857143, "max_line_length": 88, "alphanum_fraction": 0.6073883162}
angular.module('d4d')
.controller('ImageUpload', ['$log',
	function ImageUpload(vm, $log) {
        vm.upload_image = function (image) {
			if (!image.valid) return;

			var imagesRef, safename, imageUpload;
			
			image.isUploading = true;
			imageUpload = {
				isUploading: true,
				data: image.data,
				thumbnail: image.thumbnail,
				name: image.filename,
				author: {
					provider: vm.auth.user.provider,
					id: vm.auth.user.id
				}
			};

			safename = imageUpload.name.replace(/\.|\#|\$|\[|\]|-|\//g, "");
			imagesRef = new Firebase(vm.firebaseUrl + '/images');

			imagesRef.child(safename).set(imageUpload, function (err) {
				if (!err) {
					imagesRef.child(safename).child('isUploading').remove();
					vm.$apply(function () {
						vm.status = 'Your image "' + image.filename + '" has been successfully uploaded!';
						if (vm.uploaded_callback !== undefined) {
							vm.uploaded_callback(angular.copy(imageUpload));
						}
						image.isUploading = false;
						image.data = undefined;
						image.filename = undefined;
					});
				}else{
					vm.error = 'There was an error while uploading your image: ' + err;
				}
			});
		};
	}
]);