arnaucube
arnaucube/objectImageIdentifierAIPublic Self-hosted repository
objectImageIdentifierAI/smartphoneApp/www/js/main.js
smartphoneApp/www/js/main.jsRaw
 1angular.module('app.main', [])
 2
 3.controller('MainCtrl', function($scope, $http) {
 4    $scope.response = "";
 5    $scope.model_file={};
 6    
 7    $scope.uploadFile = function() {
 8        console.log("$scope.img_file");
 9        console.log($scope.img_file);
10        var fd = new FormData();
11        //Take the first selected file
12        fd.append("file", $scope.img_file);
13        console.log(fd);
14        $http({
15                url: urlapi + 'predict',
16                method: "POST",
17                headers: {
18                    "Content-Type": undefined
19                },
20                data: fd
21            })
22            .then(function(data) {
23                    console.log("response: ");
24                    console.log(data.data);
25                    // response reaction
26                    $scope.response= data.data.result;
27                },
28                function(response) { // optional
29                    // failed
30                    console.log(response);
31                });
32    };
33
34    /*$scope.takePhoto = function() {
35        alert("a");
36        console.log("take photo");
37        var options = {
38                quality: 100,
39                destinationType: Camera.DestinationType.DATA_URL,
40                sourceType: Camera.sourceType,
41                allowEdit: true,
42                encodingType: Camera.EncodingType.PNG,
43                targetWidth: 500,
44                targetHeight: 500,
45                popoverOptions: CameraPopoverOptions,
46                saveToPhotoAlbum: false,
47                correctOrientation:true
48            };
49
50            $cordovaCamera.getPicture(options).then(function(imageData) {
51                //$scope.user.newAvatar = "data:image/jpeg;base64," + imageData;
52                $scope.img.imgdata = "data:image/jpeg;base64," + imageData;
53                $scope.img.img = imageData;
54                }, function(err) {
55                console.log(err);
56            });
57    };*/
58})
59.directive('fileModel', [
60    '$parse',
61    function($parse) {
62        return {
63            restrict: 'A',
64            link: function(scope, element, attrs) {
65                var model = $parse(attrs.fileModel);
66                var modelSetter = model.assign;
67
68                element.bind('change', function() {
69                    scope.$apply(function() {
70                        if (attrs.multiple) {
71                            modelSetter(scope, element[0].files);
72                        } else {
73                            modelSetter(scope, element[0].files[0]);
74                        }
75                    });
76                });
77            }
78        };
79    }
80]);