Search code examples
javascriptfile-uploadxmlhttprequestmozilla

Error with attaching file in Mozilla 24.0


Early code had worked fine in all browsers. After updating to the new version of Mozilla got out error. In google I found only one link about this - https://bugzilla.mozilla.org/show_bug.cgi?id=796850, and I don't understand, how to get rid of problems.

TypeError: Cannot convert string to ByteString because the character at index 0 has value 1054 which is greater than 255.
xhr.setRequestHeader("X-File-Name", file.name);

In this code:

....
xhr.open('POST', get_page_url() + '?operation=upload_files');
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("X-File-Name", file.name);
xhr.send(file);
...

In file.name normal cyrillic file name with the extension.


Solution

  • I solved problem:

    xhr.setRequestHeader("X-File-Name", file.name);
    

    Replaced to..

    xhr.setRequestHeader("X-File-Name", unescape(encodeURIComponent(file.name)));