2

i have problem with encoding my text

var description = "jak używać?"
        var blob = new Blob([description], {
            type: "text/plain;charset=utf-8;"
        });
        var url = URL.createObjectURL(blob);
        console.log(url)

where i enter to url my description isnt same and return jak uĹźywaÄ? What i doing wrong?

Mateusz
  • 199
  • 1
  • 2
  • 12

3 Answers3

6

Add Byte order mark to the array header.

blob = new Blob(["\ufeff", description]);

https://stackoverflow.com/a/18925211/9867895

https://en.wikipedia.org/wiki/Byte_order_mark

lovestackh343
  • 581
  • 5
  • 6
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes https://stackoverflow.com/help/how-to-answer – Shanteshwar Inde Jan 22 '19 at 06:21
0

Try:

...

var blob = new Blob([**"\ufeff",** description], {

...

trinchet
  • 6,753
  • 4
  • 37
  • 60
Mario
  • 11
0

URL.creatObjectUrl doesn't seem to work with raw UTF-8 strings. The solution provided for binary data https://stackoverflow.com/a/36955941/70716 should work. the answers to Creating a Blob from a base64 string in JavaScript also include some additional explanation of the issue and alternative code examples.

bstoney
  • 6,594
  • 5
  • 44
  • 51