title: shortenning angular code to one method
body: <p>how can I shorten my code so I dont have to use two different methods to do a file upload for two different fields </p>
  
  <p>this is what I have</p>
  
  <pre><code>            &lt;input type="file" name="file" onchange="angular.element(this).scope().uF1(this.files)"/&gt;
  
              &lt;input type="file" name="file" onchange="angular.element(this).scope().uF2(this.files)"/&gt;
  </code></pre>
  
  <p>here is controller</p>
  
  <pre><code> $scope.upF1 = function(files) {
  
                      var fd = new FormData();
                      //Take the first selected file
                      fd.append("file", files[0]);
                      //console.log(files);
                      $http.post('/url', fd, {
                          withCredentials: true,
                          headers: {'Content-Type': undefined },
                          transformRequest: angular.identity
                      }).success( function(data){
                          $scope.image1 = data[0]['imageFileName'];
                      });
  
                  };
  
                  $scope.uF2 = function(files) {
  
                      var fd = new FormData();
                      //Take the first selected file
                      fd.append("file", files[0]);
                      //console.log(files);
                      $http.post('/url', fd, {
                          withCredentials: true,
                          headers: {'Content-Type': undefined },
                          transformRequest: angular.identity
                      }).success( function(data){
                          $scope.image2 = data[0]['imageFileName'];
                      });
  
                  };
  </code></pre>
  
  <p>you can see that I am trying to set up  $scope.image1  and  $scope.image2</p>