Garbled characters may appear when uploading Chinese files.

default discord avatar
3 weeks ago
1 2

When I upload an image and the file name is in Chinese, garbled characters appear on the webpage. How can I solve this problem?
this is the image link
I searched online and found that if the file name appears garbled when uploading using Node FormData, it may be because the file name is not encoded in UTF-8. We need to use the encodeURI() function or other encoding methods to solve this this:

const form = new FormData();
form.append('file', fs.createReadStream(filePath), encodeURI(fileName));

However, I don’t know where to place these codes. Does anyone know?

  • discord user avatar
    Payload Team
    3 weeks ago

    To fix this issue, add the following property to the upload object in your payload.config:

    upload: {
        defParamCharset: 'utf-8',

    Here is a little background as to why...

    Payload uses the express-fileupload package to manage uploads. By default, this package has defParamCharset set to latin1. However, we need a character set that supports Chinese i.e. utf-8.

    You have full control over the express-fileupload options with Payload, simply pass any valid properties to the upload object in your base payload.config.

    Note: here is the defParamCharset definition from express-fileupload:
    Screen Shot 2023-05-10 at 11 19 56 AM

    1 reply
  • default discord avatar
    3 weeks ago

    Thank you very much, the problem is solved, this problem has been bothering me for a long time.

  • discord user avatar
    Payload Team
    3 weeks ago

    Hey @clhome, I'm looking into this now 🔎

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.