Try   HackMD

I. Why need to do this?

Shift JIS (SJIS) and UTF-8 are both character encoding systems used to represent text in computers. Shift JIS is primarily used for Japanese characters, while UTF-8 is a more universal encoding that covers a wide range of characters from various languages.

When you open a Shift JIS encoded file on a non-Japanese device, the characters may appear garbled or incorrectly displayed. This is because the non-Japanese device does not understand the Shift JIS encoding.

So, that's why I'm sharing this, but i supposed we could do this with other encoding types.

II. Implementation

On backend, just make sure to set your character set to Shift_JIS.
If there are some weird character appears, we might need to tweek the string a bit, since in Shift_JIS, each character is encoded using 2 bytes (16 bits), while in UTF-8, it takes 1-4 bytes depending on the characters.

Here's the ASCII table incase you need it.

On frontend, add media type when you create the download link.

const downloadCSV = () => {
    const apiUrl = "/download"
    const res = await api.get(apiUrl, {
        responseType: 'blob',
    });
    const a = document.createElement('a');
    const url = window.URL.createObjectURL(new Blob([res.data]));
    a.href = url;
    a.target = '_blank';
    a.type = 'text/csv;charset=Shift_JIS';
    a.download = "fileName";
    document.body.appendChild(a);
    a.click();
}

That's it! It's not much but i hope it helpful somehow.
Thank you for reading.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →