title: Download file with Angular and Django
body: <p>I have a table containing a list of files fetched from the server. I also have a button, that downloads the selected file. So I made a function which call a service and it opens the response (the file) in a new window, so the user can download it.
  Controller:</p>
  
  <pre><code>  $scope.download = function() {
  
  if ($scope.cancelPromise) {
    $scope.cancelPromise.resolve();
  }
  $scope.cancelPromise = $q.defer();
  UserFileSrv.downloadFile.download(
    {
      fileId: $scope.selectedFile.id
    },function(data) {
      if (data) {
        toaster.pop('success', 'Success', 'success');
        window.open(data);
      }
    }, function(error) {
      if (error) {
        toaster.pop('error', 'Error', error);
      }
    }
  );
  </code></pre>
  
  <p>};</p>
  
  <p>The service:</p>
  
  <pre><code>angular.module('app').factory('UserFileSrv', ['$resource', function($resource) {
  var userFile = {
      downloadFile: $resource('my_url/:fileId/?', {
        fileId: '@fileId'
      }, {
        download: {
          method: 'GET',
          isArray: false
        }
      })
      };
      return userFile;
  }]);
  </code></pre>
  
  <p>The browser shows the 'success' toaster, but it opens a window which contains this string: <code>Cannot GET /%5Bobject%20Object%5D</code></p>
  
  <p>Note: the Content-Type of the response is: <code>application/json</code></p>