title: Parsing a CSV file provided by an input in Angular
body: <p>I'm creating a webapp which features uploads of .csv file.</p>
  
  <p>Instead of uploading the whole file on my server, then adding every lines in a table thanks to PHP, I'd like to parse the file in Angular, then add parsed lines (thanks to Restangular). This way, I should be able to retrieve some "errors" before uploading them (or not).</p>
  
  <p>In a view, I've created a simple file input, with a directive called file (source : <a href="http://angularjstutorial.blogspot.fr/2012/12/angularjs-with-input-file-directive.html" rel="nofollow noreferrer">http://angularjstutorial.blogspot.fr/2012/12/angularjs-with-input-file-directive.html</a>)</p>
  
  <pre><code>&lt;input type="file" data-file="param.file" /&gt;
  </code></pre>
  
  <p>The <code>file</code>directive :</p>
  
  <pre><code>app.directive('file', function(){
    return {
      scope: {
        file: '='
      },
      link: function(scope, el, attrs){
        el.bind('change', function(event){
          var files = event.target.files;
          var file = files[0];
          scope.file = file ? file.name : undefined;
          scope.$apply();
        });
      }
    };
  });
  </code></pre>
  
  <p>This way, I can retrieve when the user chooses a file. Unfortunately, I'm getting only the file name.</p>
  
  <p>I'd like to parse the csv in a string, which i'll split thanks to this filter (source : <a href="https://stackoverflow.com/questions/24080602/parsing-csv-in-javascript-and-angularjs">parsing CSV in Javascript and AngularJS</a>) :</p>
  
  <pre><code>app.filter('csvToObj',function(){
    return function(input){
      var rows=input.split('\n');
      var obj=[];
      angular.forEach(rows,function(val){
        var o=val.split(';');
        obj.push({
          designation:o[1],
          ...
          km:o[11]
        });
      });
      return obj;
    };
  });
  </code></pre>
  
  <p>How can I retrieve the data in the csv file provided by the input instead of the file name ?</p>
  
  <p>Thanks in advance.</p>