Skip to content

fix: preserve correct Content-Type for inline file preview#37545

Open
ifer47 wants to merge 1 commit into
langgenius:mainfrom
ifer47:fix/file-preview-content-type
Open

fix: preserve correct Content-Type for inline file preview#37545
ifer47 wants to merge 1 commit into
langgenius:mainfrom
ifer47:fix/file-preview-content-type

Conversation

@ifer47

@ifer47 ifer47 commented Jun 16, 2026

Copy link
Copy Markdown

Summary

  • The /file-preview endpoint unconditionally sets Content-Type: application/octet-stream, overriding the correct MIME type (upload_file.mime_type) even for inline previews where as_attachment=False
  • This causes browsers to download files instead of displaying them inline (e.g., PDFs, images, audio/video)
  • Moved the Content-Type override inside the if args.as_attachment: block so it only applies for downloads, matching the pattern already used in the service API endpoint (controllers/service_api/app/file_preview.py)

Test plan

  • Verify that a file preview request (without as_attachment) returns the correct Content-Type matching the file's MIME type
  • Verify that a file download request (with as_attachment=True) still returns Content-Type: application/octet-stream
  • Verify that enforce_download_for_html still forces application/octet-stream for HTML content (security measure preserved)

Closes #37198

🤖 Generated with Claude Code Best

The /file-preview endpoint unconditionally set Content-Type to
application/octet-stream, overriding the correct MIME type from
upload_file.mime_type even when as_attachment=False (inline preview).
Now the override only applies when downloading as an attachment,
matching the pattern already used in the service API endpoint.

Closes langgenius#37198

Co-Authored-By: zhipu/glm-5 <zai-org@claude-code-best.win>
@ifer47 ifer47 requested a review from QuantumGhost as a code owner June 16, 2026 16:59
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File preview returns Content-Type: application/octet-stream on v1.14.2 with local storage, causing browser download instead of inline preview

1 participant