fix(upload): preserve original filename for downloads#512
Merged
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_namewas 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_namecolumn on upload. The download route'sderiveFilenamealready prefersimage_name(RFC 5987filename*=UTF-8''…), so no download-route or migration change is needed — only the upload payload.multiple-file-upload/livephoto-file-upload: includeimage_name(the uploaded file's name) in the insert payload;simple-file-uploadalready did.hono/imagesPOST: reduceimage_nameto a bare basename (defense-in-depth) before insert; empty/whitespace falls back to the URL-derived name (prior behaviour).Test plan
image_nameis the original; storage keys stay unique.foo.jpg, andimage_nameisfoo.jpg(post-conversion, matching the bytes), notfoo.heic.Note: these upload components carry pre-existing loose typing (e.g.
res?.data?.urlpassed where astringis expected, one stale@ts-expect-error); this change introduces no new type errors.🤖 Generated with Claude Code