Skip to content

fix: don't blanket-override Content-Type to octet-stream for file-preview#37243

Open
1795771535y-cell wants to merge 2 commits into
langgenius:mainfrom
1795771535y-cell:fix/file-preview-content-type-37198
Open

fix: don't blanket-override Content-Type to octet-stream for file-preview#37243
1795771535y-cell wants to merge 2 commits into
langgenius:mainfrom
1795771535y-cell:fix/file-preview-content-type-37198

Conversation

@1795771535y-cell

Copy link
Copy Markdown
Contributor

Summary

Fixes #37198

The /files/{id}/file-preview endpoint unconditionally set Content-Type: application/octet-stream after the Response constructor had already used upload_file.mime_type, causing browsers to force-download all files instead of previewing them inline.

Root Cause

In controllers/files/image_preview.py, line 137:
response.headers["Content-Type"] = "application/octet-stream"
was outside the if args.as_attachment block, overriding the correct mimetype for ALL requests.

Fix

Move the octet-stream override inside the as_attachment conditional, so it only applies when the caller explicitly requests download-as-attachment.

Before/After

Scenario Before After
Inline preview (image/png) octet-stream -> download image/png -> browser inline
Inline preview (pdf) octet-stream -> download application/pdf -> inline
Attachment download octet-stream octet-stream (unchanged)

Changes

1 line moved - Content-Type override from unconditional to conditional (under as_attachment branch).

…tening elements

When _truncate_array breaks due to size limit exceeding target_size, the
truncated flag was not set to True, causing dropped tail elements to go
unreported. Additionally, the flag was overwritten (truncated =
part_result.truncated) instead of accumulated, so a later fitting element
could reset a previously-set flag to False.

Fix by setting truncated = True before the size-limit break, and using
logical OR to accumulate (truncated = truncated or part_result.truncated).

Fixes langgenius#37192

Signed-off-by: C4P-T <cap@teamos.dev>
…view

The /files/{id}/file-preview endpoint unconditionally set Content-Type to
application/octet-stream after the Response constructor had already used
the correct upload_file.mime_type, causing all inline previews (images,
PDFs, etc.) to be forced as downloads instead of rendering in-browser.

Move the octet-stream override inside the as_attachment branch so it
only applies when the caller explicitly requests download-as-attachment.
For normal previews, the original mime_type from the Response constructor
is preserved.

Fixes langgenius#37198

Signed-off-by: C4P-T <cap@teamos.dev>
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 47.25% 47.25% 0.00%
Strict coverage 46.75% 46.75% 0.00%
Typed symbols 26,553 26,553 0
Untyped symbols 29,962 29,962 0
Modules 2853 2853 0

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