payloadcms / payloadcms/payload

Upload with filename with trailing space is broken using GCS client uploads

Open
#15,352 2 comments 0 reactions 1 assignee View on GitHub

@paulpopus is already working on this.

Since Jan 27, 2026.

created-by: Contributor plugin: storage-*
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

Describe the Bug

https://github.com/payloadcms/payload/blob/4181a1235b39d27aa5427e89fcc2fed21a8d2972/packages/payload/src/uploads/generateFileData.ts#L261

sanitize-filename library is removing trailing spaces in filename, but if using clientUploads - google cloud storage receives original filename, resulting in broken upload .

Cliend uploads have some other bugs too (like double-uploading and server performance issues with client uploads) #14768

In my case, i generate direct link to GCS to bypass traffic from my server , directly to GCS , but i can't do that properly, because beforechange hook receives already sanitized filename.

Payload api doesn't work too (404)

Image
Link to the code that reproduces this issue

https://github.com/payloadcms/payload/blob/4181a1235b39d27aa5427e89fcc2fed21a8d2972/packages/payload/src/uploads/generateFileData.ts#L261

Reproduction Steps

Prepeare file with space in the end

Image

Upload it (with clientUploads:true)

Image

Already admin panel having some issues

Image Image

When saving, we have sanitized filename in admin panel

Image

But file saved in GCS have original filename,which results in inaccessible file

Image

And 404 on API

Image
Which area(s) are affected?

plugin: storage-*

Environment Info
Binaries:
  Node: 22.16.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.22.0
Relevant Packages:
  payload: 3.69.0
  next: 15.4.10
  @payloadcms/db-mongodb: 3.69.0
  @payloadcms/graphql: 3.69.0
  @payloadcms/live-preview: 3.69.0
  @payloadcms/live-preview-react: 3.69.0
  @payloadcms/next/utilities: 3.69.0
  @payloadcms/plugin-cloud-storage: 3.69.0
  @payloadcms/plugin-nested-docs: 3.69.0
  @payloadcms/richtext-lexical: 3.69.0
  @payloadcms/sdk: 3.69.0
  @payloadcms/storage-gcs: 3.69.0
  @payloadcms/translations: 3.69.0
  @payloadcms/ui/shared: 3.69.0
  react: 19.2.1
  react-dom: 19.2.1
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.