Skip to content

fix: use correct Content-Type in file-preview endpoint for non-download requests#37553

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

fix: use correct Content-Type in file-preview endpoint for non-download requests#37553
GautamKumarOffical wants to merge 1 commit into
langgenius:mainfrom
GautamKumarOffical:fix/file-preview-content-type

Conversation

@GautamKumarOffical

Copy link
Copy Markdown

Problem

The /files/{file_id}/file-preview endpoint was unconditionally overriding Content-Type to application/octet-stream on every response, regardless of whether the request was a preview or a download.

This meant that when users tried to preview images or PDFs inline in the browser, the browser received Content-Type: application/octet-stream and was forced to download the file instead of rendering it. This was a regression from v1.12.1 where the correct MIME type was returned.

Root Cause

In api/controllers/files/image_preview.py:135, the line that sets Content-Type to application/octet-stream was outside the if args.as_attachment: guard, so it ran for every request — both preview and download.

Fix

Moved the Content-Type override inside the as_attachment guard so it only applies when the client explicitly requests a download. For preview requests, the correct MIME type (set via the mimetype parameter when constructing the Flask Response) is preserved.

Testing

Updated the existing unit test in test_image_preview.py to expect the correct MIME type (text/plain) for non-attachment preview requests, rather than the incorrect application/octet-stream.

Fixes #37198

…ad requests

The /files/{file_id}/file-preview endpoint was unconditionally overriding
Content-Type to application/octet-stream, even for preview requests where
as_attachment is false. This caused browsers to force-download files instead
of rendering them inline (e.g., images, PDFs).

The fix moves the Content-Type override inside the as_attachment guard so it
only applies when the client explicitly requests a download.

Fixes langgenius#37198
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 48.59% 48.59% 0.00%
Strict coverage 48.10% 48.10% 0.00%
Typed symbols 27,995 27,995 0
Untyped symbols 29,922 29,922 0
Modules 2892 2892 0

@GautamKumarOffical

Copy link
Copy Markdown
Author

Hi! This PR fixes a content-type issue in the file-preview endpoint. All checks are passing. Happy to make any adjustments. Thanks for reviewing!

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