Skip to content

fix(upload): preserve original filename for downloads#512

Merged
Zheaoli merged 1 commit into
mainfrom
fix/preserve-original-filename
May 31, 2026
Merged

fix(upload): preserve original filename for downloads#512
Zheaoli merged 1 commit into
mainfrom
fix/preserve-original-filename

Conversation

@Zheaoli
Copy link
Copy Markdown
Collaborator

@Zheaoli Zheaoli commented May 31, 2026

Problem

After upload the original filename was discarded: the storage key is generated as {cuid}.{ext} (randomized so same-named files don't collide), image_name was left null, and the multi-image uploader never sent it. So a downloaded file got the random ID as its name instead of the original.

Fix

Persist the original (post-HEIC-conversion) filename in the existing image_name column on upload. The download route's deriveFilename already prefers image_name (RFC 5987 filename*=UTF-8''…), so no download-route or migration change is needed — only the upload payload.

  • multiple-file-upload / livephoto-file-upload: include image_name (the uploaded file's name) in the insert payload; simple-file-upload already did.
  • hono/images POST: reduce image_name to a bare basename (defense-in-depth) before insert; empty/whitespace falls back to the URL-derived name (prior behaviour).
  • The storage key stays randomized, so same-named files in a batch don't overwrite each other; the original name is used only for display and the download default.

Test plan

  • Upload several images (incl. a batch with duplicate names + one non-ASCII name) → DB image_name is the original; storage keys stay unique.
  • Download each → default filename is the original (non-ASCII not garbled, via RFC 5987).
  • Upload a HEIC → stored as foo.jpg, and image_name is foo.jpg (post-conversion, matching the bytes), not foo.heic.
  • Image with empty/no name → falls back to the URL-derived name (unchanged behaviour).

Note: these upload components carry pre-existing loose typing (e.g. res?.data?.url passed where a string is expected, one stale @ts-expect-error); this change introduces no new type errors.

🤖 Generated with Claude Code

Uploads stored the original name only in the randomized storage key
({cuid}.{ext}), leaving image_name null, so the download
Content-Disposition fell back to the random ID. The multi-image upload
never sent image_name at all.

Store the original (post-HEIC-conversion) filename in the existing
image_name column on upload; the download route's deriveFilename already
prefers it (RFC 5987 encoded), so no download or migration change is
needed. The storage key stays randomized so same-named files in a batch
don't collide — the original name is used only for display and the
download default.

- multiple-file-upload / livephoto-file-upload: send image_name (the
  uploaded file's name); simple-file-upload already did.
- hono/images POST: reduce image_name to a bare basename
  (defense-in-depth) before insert; empty falls back to the URL name.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
picimpact Ready Ready Preview, Comment May 31, 2026 6:45pm

@Zheaoli Zheaoli merged commit f9bf2ea into main May 31, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant