1

I am getting filename from file obj in javascript and sending the same to server using AJAX.

var uploadFile = document.getElementById("uploadFile");
var filename = uploadFile.files[0].name;

The problem is non English characters found in filename such as 'çõ' and the chars converted to "�". I also set "Content-Type=text/html; charset=UTF-8" in the page.

How can I solve this problem?

Note: This problem occurs only in windows laptops

Benjamin Toueg
  • 10,511
  • 7
  • 48
  • 79
Magesh
  • 11
  • 4
  • 1
    Where do the chars become unreadable? If it's in the server, it's a server problem, not a js problem. – bfavaretto Oct 10 '13 at 20:17
  • The filename converted to unreadable in js and the converted value sending to server. I have seen in Developer Console -> Network -> Headers – Magesh Oct 10 '13 at 20:20
  • http://stackoverflow.com/questions/546365/utf-8-text-is-garbled-when-form-is-posted-as-multipart-form-data – peterfoldi Oct 10 '13 at 20:44
  • UTF-8 needs to be all the way through your system -- the files you read need to be in UTF-8, as do the actual program files. The database encoding too. And the encoding specified in the `content-type`. If you have a mismatch of encoding types anywhere through your system, it can result in this kind of error. – Spudley Oct 10 '13 at 21:03
  • I think this is not a server side problem. Because, if it's a server side problem, the encoding issue will occur for all users. But, this problem occurs only for some users. – Magesh Oct 10 '13 at 21:07
  • [JavaScript uses UTF16](http://www.ecma-international.org/ecma-262/5.1/#sec-4.3.16). – Raymond Chen Oct 11 '13 at 13:32

1 Answers1

0

I solved the problem:

filename = unescape(encodeURIComponent(filename));
Magesh
  • 11
  • 4