DEV Community

Macus Desir
Macus Desir

Posted on

JS File upload: Detect Encoding

I'm currently stuck on this same issue but in Angular 6, where I have to determine the file encoding type which can vary from csv to csv. I've found an npm package called jschardet but it only detects after the file is read. Along with a few others that seem to have the same issue. I've found something that mentioned the upload stream but I'm still looking into what this is. I also went to google and I was able to find my exact issue but with no clear solution. I feel like the stackoverflow explains it a little better though. So here I am, at the mercy of the internet. What can I do?

JS File upload: Detect Encoding

2

So, I'm trying to write a CSV-file importer using AngularJS on the frontend side and NodeJS for the backend My problem is, that I'm not sure about the encoding of the incoming CSV files. Is there a way to automatically detect it?

I first tried to use FileReader.readAsDataURL() and do…

Top comments (1)

Collapse
 
guillim profile image
Guillim

the answer probably is FileReader.readAsBinaryString() used with some library like jschardet.

More info on this blogpost