You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.6 KiB

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