0

I want to read a CSV file as binary format to send to an API.

I use the following HTML input - file

<input type="file" name=filedata (change)="fileChangeEvent($event)" />

fileChangeEvent(e)
{
  var fileData, file = e.target.files[0], reader = new FileReader();
  if (!file) {
    return;
  }
  reader.onload = function(e) {
  };
  reader.readAsBinaryString(file);
}

But, I am getting the following error

ERROR TypeError: Object doesn't support property or method 'readAsBinaryString'

  • 3
    see [this documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsBinaryString) - firstly, `readAsBinaryString` is deprecated, and secondly, never supported in Internet Exploder - which browser are you attempting this with – Jaromanda X Jun 09 '17 at 08:39
  • [Please don't put tags in question titles](https://stackoverflow.com/help/tagging) – Liam Jun 09 '17 at 08:54
  • Possible duplicate of [How to read data From \*.CSV file using javascript?](https://stackoverflow.com/questions/7431268/how-to-read-data-from-csv-file-using-javascript) – Liam Jun 09 '17 at 08:55
  • I am using IE @Jaromanda X –  Jun 09 '17 at 09:45
  • I want to convert file data to binary format, not duplicate question @Liam –  Jun 09 '17 at 09:46
  • I tried your documentation @Jaromanda X, not able to resolve issue –  Jun 09 '17 at 09:46
  • did you read my first comment? IE does not and never has supported the now deprecated `readAsBinaryString` - the suggested alternative is `readAsArrayBuffer` - but that is only supported in IE10+ - typically, you just say you are using "IE" ... should I gaze into my crystal ball to discover which version of that most hated steam powered browser you are vainly hanging on to for god knows what reason? – Jaromanda X Jun 09 '17 at 09:51
  • I am using IE 11, I tried with readAsArrayBuffer, coming empty array with no data. I tried in chrome too. Same issue exists @Jaromanda X –  Jun 09 '17 at 09:55
  • Does Internet Exploder handle this -> https://jsfiddle.net/pk3L7kh6/ – Jaromanda X Jun 09 '17 at 10:02
  • `Same issue exists` - if the same issue exists, then you're still trying to use `readAsBinaryString` rather than `readAsArrayBuffer` – Jaromanda X Jun 09 '17 at 10:04

0 Answers0