fix(api): preserve inline image mime type on /file-preview (#40479) - #41266
Open
Taranum01 wants to merge 2 commits into
Open
fix(api): preserve inline image mime type on /file-preview (#40479)#41266Taranum01 wants to merge 2 commits into
Taranum01 wants to merge 2 commits into
Conversation
…s#40479) Rebased onto upstream/main (HEAD c7520d7). Conflicts resolved: - api/controllers/files/image_preview.py: kept upstream's _is_svg_content() + SVG-specific Content-Type/X-Content-Type-Options handling, AND kept my fix that only forces application/octet-stream when as_attachment=True (or is_svg=True, per upstream's broader condition). Inline previews still preserve the upload's real mime type so image/audio/video render in the logs UI. - api/tests/unit_tests/controllers/files/test_image_preview.py: kept upstream's new test_inline_preview_uses_upload_file_mimetype() (which uses _upload_file() helper for a real PDF file with size=100) and relaxed my assertions to expect application/pdf rather than text/plain. Added my image/png regression fixture as an additional test case. Issue langgenius#40479 is fixed: image previews no longer force octet-stream for inline (as_attachment=False) responses.
Taranum01
force-pushed
the
fix/40479-image-preview-mime
branch
from
August 25, 2026 20:23
b84f734 to
b6cd588
Compare
Contributor
Pyrefly Type Coverage
|
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-08-25 20:35:58.208155150 +0000
+++ /tmp/pyrefly_pr.txt 2026-08-25 20:35:48.386046645 +0000
@@ -3529,13 +3529,15 @@
ERROR `SimpleNamespace` is not assignable to attribute `request` with type `Request` [bad-assignment]
--> tests/unit_tests/controllers/files/test_image_preview.py:99:26
ERROR `SimpleNamespace` is not assignable to attribute `request` with type `Request` [bad-assignment]
- --> tests/unit_tests/controllers/files/test_image_preview.py:143:26
+ --> tests/unit_tests/controllers/files/test_image_preview.py:145:26
ERROR `SimpleNamespace` is not assignable to attribute `request` with type `Request` [bad-assignment]
- --> tests/unit_tests/controllers/files/test_image_preview.py:176:26
+ --> tests/unit_tests/controllers/files/test_image_preview.py:183:26
ERROR `SimpleNamespace` is not assignable to attribute `request` with type `Request` [bad-assignment]
- --> tests/unit_tests/controllers/files/test_image_preview.py:210:26
+ --> tests/unit_tests/controllers/files/test_image_preview.py:216:26
ERROR `SimpleNamespace` is not assignable to attribute `request` with type `Request` [bad-assignment]
- --> tests/unit_tests/controllers/files/test_image_preview.py:242:26
+ --> tests/unit_tests/controllers/files/test_image_preview.py:250:26
+ERROR `SimpleNamespace` is not assignable to attribute `request` with type `Request` [bad-assignment]
+ --> tests/unit_tests/controllers/files/test_image_preview.py:282:26
ERROR No attribute `global_db` in module `controllers.files.tool_files` [missing-attribute]
--> tests/unit_tests/controllers/files/test_tool_files.py:25:5
ERROR `SimpleNamespace` is not assignable to attribute `request` with type `Request` [bad-assignment]
|
…yUploadFile (langgenius#40479) Per Pyrefly type-check feedback on langgenius#41266: the regression test I added referenced a DummyUploadFile class that doesn't exist in this module — the upstream test file uses an _upload_file() helper instead. Switched the call site to match. The remaining Pyrefly errors (Request type vs SimpleNamespace) are pre-existing in the test module and not introduced by this PR.
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.
Closes #40479
Problem
/files/{id}/file-previewwas forcingContent-Type: application/octet-streamon every response — including the inline previews that the logs UI uses to render user-uploaded and generated images. The browser received a generic binary blob, so every image preview in the logs (file uploads and generated outputs) showed up as a broken icon.The intended behavior:
as_attachment=False) → keep the upload's real mime type so the browser can render images, audio, video inlineas_attachment=True) → forceapplication/octet-streamso the browser treats it as a file downloadThe previous code forced octet-stream unconditionally.
Fix
In
api/controllers/files/image_preview.py, only override Content-Type whenas_attachment=True. Inline previews now preserveupload_file.mime_type(image/png, image/jpeg, audio/mpeg, video/mp4, application/pdf, ...).This matches the behavior described in PR #40397 (which was closed without merging) for the inline-preview side of the fix.
Verification
New regression fixture
test_inline_image_preview_preserves_image_mimeasserts the exact image/png case from the bug report. Updatedtest_basic_streamto assert inline previews no longer forceapplication/octet-streamwhiletest_as_attachmentstill verifies the download path keeps forcing it.