Skip to content

fix: serve profile images with correct MIME type (closes #6) - #30

Merged
TusharW4ni merged 1 commit into
mainfrom
fix/image-mime-type
Aug 22, 2026
Merged

fix: serve profile images with correct MIME type (closes #6)#30
TusharW4ni merged 1 commit into
mainfrom
fix/image-mime-type

Conversation

@TusharW4ni

Copy link
Copy Markdown
Contributor

Problem (#6)

server/api/users/[id]/profile.get.ts served every uploaded profile image with a hardcoded Content-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 the Content-Type, falling back to application/octet-stream only if detection fails. Works for already-stored files too (no upload change or DB migration needed).

const detected = await fileTypeFromFile(filePath)
setHeader(event, 'Content-Type', detected?.mime ?? 'application/octet-stream')

Verification

  • pnpm build succeeds — file-type bundles into the Nitro output.
  • Runtime check: fileTypeFromFile on a real PNG returns { ext: 'png', mime: 'image/png' }.
  • CI (pnpm test) runs on this PR.

Closes #6.

🤖 Generated with Claude Code

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>
@TusharW4ni
TusharW4ni merged commit 8717e9d into main Aug 22, 2026
1 check passed
@TusharW4ni
TusharW4ni deleted the fix/image-mime-type branch August 22, 2026 23:37
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.

Bug: Correctly serve Image MIME types from local storage

1 participant