I have been looking answer for this question for days. Actually, I need to upload the ansi encoded csv file to web service. The front end application reads the file encode it's content to base64 and send it to web service in json format. But when I try to read file with javascript, non-english unicodes just gets changed to something else.
Is there any way to read ansi encoded csv file in javascript and converting its encoding to utf-8?
With my research, I think is impossible. The file must be in UTF-8 itself.
Any suggestions would be great help.
I have been looking answer for this question for days. Actually, I need to upload the ansi encoded csv file to web service. The front end application reads the file encode it's content to base64 and send it to web service in json format. But when I try to read file with javascript, non-english unicodes just gets changed to something else.
Is there any way to read ansi encoded csv file in javascript and converting its encoding to utf-8?
With my research, I think is impossible. The file must be in UTF-8 itself.
Any suggestions would be great help.
Share Improve this question edited Jun 10, 2015 at 10:24 Kirill Slatin 6,1733 gold badges21 silver badges38 bronze badges asked Jun 10, 2015 at 5:00 Mani RaiMani Rai 7042 gold badges10 silver badges26 bronze badges 1- 1 You mean ISO 8859-1 or Windows CP1252? – FlavorScape Commented Jun 10, 2015 at 5:11
1 Answer
Reset to default 5I am sorry I misread you question at first. Your trouble es at the moment of reading the file. It is useless to try to convert the file after contents were ruined when trying to load in a wrong encoding. I came up with FileReader API in this fiddle inspired by this example and article on html5rocks
var r = new FileReader();
r.readAsText(f, 'windows-1252');
The only trouble I see here is there is no auto encoding detection. You need to know encoding before loading the file.