Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File names turn into gibberish when uploading via the Uploads interface (Media) #8107

Closed
roi-polisave opened this issue Sep 7, 2024 · 4 comments

Comments

@roi-polisave
Copy link

Link to reproduction

No response

Environment Info

PayloadCMS: 3.0.0-beta.100 (but the issue also happens on older versions)
Browser versions: Tested on Chrome (version 126) and Firefox (version 130).
Operating System: MacOS
Node.js: v20.17.0
Next.js: 15.0.0-canary.104 (but the issue also happens on older versions)

Describe the Bug

I’ve encountered an issue where file names turn into gibberish when uploading files through the Payload CMS Uploads interface. This happens with files that have non-ASCII characters (e.g., Hebrew or Japanese file names). I have tested this on both Chrome and Firefox browsers on a MacOS system.

I found that there was a similar issue in Postman (issue reference: Postman GitHub Issue #5912), where multipart/form-data requests with non-ASCII file names were being altered. This might indicate a similar encoding issue in Payload CMS and could be related to how the encoding is handled in the request headers.

Examples:

  1. Original file name: フェニックス.png (Japanese)
    After upload: ãã§ããã¯ã¹.png

  2. Original file name: בדיקה.png (Hebrew)
    After upload: ×××ק×.png

  3. Original file name: 検査.png (Japanese)
    After upload: æ¤æ».png

Reproduction Steps

  1. Navigate to the Uploads section (Media Collection) in the Payload CMS admin interface.
  2. Upload a file with a name containing non-ASCII characters (e.g., Hebrew or Japanese).
  3. After the file is uploaded, check the file name – it appears as gibberish instead of the original name.

Adapters and Plugins

No response

@roi-polisave roi-polisave added status: needs-triage Possible bug which hasn't been reproduced yet v3 labels Sep 7, 2024
@r1tsuu
Copy link
Member

r1tsuu commented Sep 10, 2024

For now, you can define in your root config:

upload: {
  defParamCharset: "utf8"
}

PR #8157 to make it default

@r1tsuu r1tsuu closed this as completed Sep 10, 2024
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Sep 10, 2024
r1tsuu added a commit that referenced this issue Sep 10, 2024
## Description

Fixes #8107

This has been confusing for people from countries where characters
aren't latin, for example the Japanese file name:
フェニックス.png
Turns into:
 ãã§ããã¯ã¹.png  

Additionally, ensures type-safety for `DEFAULT_OPTIONS` and removes
unused `fileHandler` property from there, which isn't defined in the
`FetchAPIFileUploadOptions` type.

## Type of change

<!-- Please delete options that are not relevant. -->

- [x] Bug fix (non-breaking change which fixes an issue)
## Checklist:

- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] Existing test suite passes locally with my changes
- [ ] I have made corresponding changes to the documentation
Copy link
Contributor

🚀 This is included in version v3.0.0-beta.103

@roi-polisave
Copy link
Author

Thank you very much, I checked and it works :)

Copy link
Contributor

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants