title: ng-file-upload with multer, success not called, and upload called repeatedly
body: <p>I'm using <a href="https://github.com/danialfarid/ng-file-upload" rel="nofollow">ng-file-upload</a> to upload an image to a node/express server from an  Angular client. </p>
  
  <p>The image is being loaded, however the 'success' method is not being called and the image upload seems to be called multiple times, causing the image to be repeatedly uploaded to the server.</p>
  
  <p>Here's my HTML form:</p>
  
  <pre><code>&lt;form accept-charset="UTF-8" ng-submit="uploadPic(picFile)" name="myForm"&gt;
  
              &lt;br&gt;Photo:
              &lt;input type="file" ngf-select ng-model="picFile" ngf-multiple="false" name="file" accept="image/*" ngf-max-size="2MB" required /&gt;
              &lt;br&gt;
  
              &lt;i ng-show="myForm.file.$error.maxSize"&gt;File too large {{picFile.size / 1000000|number:1}}MB: max {{picFile.$errorParam}}&lt;/i&gt;
  
              &lt;img ng-show="myForm.file.$valid" ngf-src="!picFile.$error &amp;&amp; picFile" class="thumb"&gt;
  
              &lt;br&gt;
  
              &lt;button class="btn btn-info" type="submit"&gt;Submit&lt;/button&gt;
              &lt;span class="progress" ng-show="picFile.progress &gt;= 0"&gt;
                &lt;div style="width:{{picFile.progress}}%" ng-bind="picFile.progress + '%'" class="ng-binding"&gt;&lt;/div&gt;
              &lt;/span&gt;
              &lt;span ng-show="picFile.result"&gt;Upload Successful&lt;/span&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>Here's my JS:</p>
  
  <pre><code>    $scope.uploadPic = function (file) {
  
          file.upload = Upload.upload({
              url: '/uploads',
              method: 'POST',
              fields: {
                  username: $scope.username
              },
              file: file,
              fileFormDataName: 'photo'
          });
  
          file.upload.then(function (response) {
              console.log("Postcontroller: upload then ");
              $timeout(function () {
                  file.result = response.data;
              });
          }, function (response) {
              if (response.status &gt; 0)
                  $scope.errorMsg = response.status + ': ' + response.data;
          });
  
          file.upload.progress(function (evt) {
              // Math.min is to fix IE which reports 200% sometimes
              file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
              console.log("PostController: upload progress " + file.progress);
          });
  
          file.upload.success(function (data, status, headers, config) {
              // file is uploaded successfully
              console.log('file ' + config.file.name + 'is uploaded successfully. Response: ' + data);
          });
      }
  </code></pre>
  
  <p>Here's my server side code:</p>
  
  <pre><code>var multer = require('multer');
  var upload = multer({ dest: './public/images'});
  
  router.post('/uploads', upload.single('file'), function(req,res,next){
    console.log("Server: got file ");
  });
  </code></pre>
  
  <p>I read somewhere that the shim library must be included first, but I've tried swapping the load order and no joy. Here are my import lines:</p>
  
  <pre><code> &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;script src="/lib/ng-file-upload/ng-file-upload-shim.js"&gt;&lt;/script&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"&gt;&lt;/script&gt;
  &lt;script src="/lib/ng-file-upload/ng-file-upload.min.js"&gt;&lt;/script&gt;
  
  &lt;script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.13/angular-ui-router.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Also, looking in the Chrome debug tools - the upload shows a status of 'pending'. The image is definitely on the server and the progress bar (in the html) shows 100%. Yet, a minute or so later, another copy of the image appears in the folder (this behaviour seems to loop) and the ng-file-upload 'success' event is never called.</p>
  
  <p>Grateful for help.</p>