title: How do i force download Video in AngularJs from Amazon S3?
body: <p>I have written code to download a video uploaded to amazon s3 using aws javascript sdk. Everything works fine but for some videos open up in the browser and start playing. Here is the code below:</p>
  
  <p>View:</p>
  
  <pre><code>&lt;a href="#" ng-click="downloadVideo(video)"&gt;Download Video&lt;/a&gt;
  </code></pre>
  
  <p>Controller: </p>
  
  <pre><code>$scope.downloadVideo = function (video) {
              videoLocation = video.video_location;
              var bucketPath = videoLocation.substring(0, videoLocation.lastIndexOf("/") + 1);
              bucketPath = bucketPath.substring(0, bucketPath.length - 1);
              var fileName = videoLocation.substring(videoLocation.lastIndexOf("/") + 1, videoLocation.length);
              var videoSignedUrl = VideoFactory.downloadVideo(bucketPath,fileName);            
              $window.open(videoSignedUrl);
          }
  </code></pre>
  
  <p>VideoFactory :</p>
  
  <pre><code>downloadVideo: function (bucketPath,fileName) {
      bucketName = aws.bucket_name;
  
      options = {
          accessKeyId : 'XXXXXXXXXXXXXXXXXXXXX',
          secretAccessKey : 'XXXXXXXXXXXXXXXXXXXXXXXXXXX',
          region : 'XXXXXX'
      }
  
      var params = {
          Bucket: bucketName + '/'+ bucketPath, Key: fileName, Expires: 60
      };
  
      var s3 = new AWS.S3(options);
      var url = s3.getSignedUrl('getObject', params);
      return url;
  }
  </code></pre>
  
  <p>So when videos open up in a new window they start getting downloaded at the bottom of the browsers. But for some unknown videos they open up in a window and start playing. How can i stop this in angularjs. What is the suggested workaround and how do others handle this kind of issues??</p>
  
  <p>I did google but most of the stackoverflow answers here say to open files in window and browsers automatically downloads it. </p>