fix: serve profile images with correct MIME type (closes #6) - #30
Merged
Conversation
Detect the image MIME type from magic bytes with file-type instead of hardcoding application/octet-stream, so profile pictures render reliably across browsers instead of being downloaded. Closes #6. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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 (#6)
server/api/users/[id]/profile.get.tsserved every uploaded profile image with a hardcodedContent-Type: application/octet-stream(files are stored without an extension). Strict browsers then download the image instead of rendering it in an<img>.Fix
Detect the real MIME type from the file's magic bytes with
file-type(Option A in the issue) and set it as theContent-Type, falling back toapplication/octet-streamonly if detection fails. Works for already-stored files too (no upload change or DB migration needed).Verification
pnpm buildsucceeds —file-typebundles into the Nitro output.fileTypeFromFileon a real PNG returns{ ext: 'png', mime: 'image/png' }.pnpm test) runs on this PR.Closes #6.
🤖 Generated with Claude Code