I would like to know how I can get the contents of a file containing special characters with a FileReader object.
<form enctype="multipart/form-data"> <input type="file" id="file" name="file"> </form>
<script> $('#file').change(function () { var file = document.getElementById('file').files[0]; var reader = new FileReader(); reader.onload = function (event) { var file_content = event.target.result; console.log(file_content); } reader.readAsBinaryString(file); } </script>
this code prints
"line1line2"
besides my file contents
line1 line2
How can I get?
line1\nline2
I tried the readAsBinaryString and readAsText methods without any success. Am I doing something wrong? thank you
Filereader doc
change
JSfiddle example http://jsfiddle.net/yTgp7/


The problem only exists in Firefox on mac Os X
source share