0

The user uploads CSV with accented characters like émily, ástha which I need to encode and pass to the backend. I have tried updating the file type in FormData between type: 'text/plain' and type: 'text/csv'.

const data = new FormData()
data.append('file', new Blob([params.file], { type: 'text/csv' }))

Passed encoding in FileReader's method readAsText with params ISO-8859-1, ISO-8859-4, ISO-10646-UCS-Basic, and a couple of other examples from http://www.iana.org/assignments/character-sets/character-sets.xhtml. Needless to say, tried other unhelpful methods readAsArrayBuffer and readAsBinaryString.

reader.readAsText(file, 'ISO-8859-4')

Printing using ISO-8859-1 gives me Žmily and ‡stha which are not close enough. I need to be able to receive the exact characters (backend uses ascii folding filter to convert these into ascii).

I am relying on How to encode & decode non Ascii characters? as the last solution.

Any pointers on how can I attempt encoding non ascii characters?

1 Answer 1

1

This might be related with the csv encoding issue. You can prepend the Byte-Order-Mark (BOM) to csv content first, try

const BOM = "\uFEFF"; 

new Blob([BOM + params.file], { type: 'text/csv;charset=utf-8' })
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, @anthony. Turns out the file uploaded was not in utf-8 format. It worked after updating the encoding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.