fix: don't blanket-override Content-Type to octet-stream for file-preview#37243
Open
1795771535y-cell wants to merge 2 commits into
Open
fix: don't blanket-override Content-Type to octet-stream for file-preview#372431795771535y-cell wants to merge 2 commits into
1795771535y-cell wants to merge 2 commits into
Conversation
…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>
Contributor
Pyrefly Type Coverage
|
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.
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
Changes
1 line moved - Content-Type override from unconditional to conditional (under as_attachment branch).