feat: add download button to PDF/image preview header#206
Open
tiger0425 wants to merge 1 commit into
Open
Conversation
Chrome's embedded PDF viewer ignores Content-Disposition headers and generates UUID-based filenames when users click its toolbar download button. This adds an explicit download button in the preview header that uses <a download> with the original filename, bypassing the viewer's internal download logic. - Hoist useBlobUrl hook to parent CodeEditorBinaryFile component so blobUrl is shared between the preview and the download button - Add download icon in headerTopBar, visible for PDF and image files - No backend changes, no new dependencies
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.
Problem
When users preview a PDF file in the code editor, Chrome's embedded PDF viewer ignores the
Content-Dispositionheader and generates a random UUID filename on download (e.g.a1b2c3d4-e5f6-7890-abcd-ef1234567890.pdf) instead of the actual file name.This is a known Chrome limitation — the built-in PDF viewer uses an internal blob URL and the HTTP
filenameparameter has no effect.Solution
Add an explicit Download button in the preview header bar (
headerTopBar). When clicked,<a download="{original-filename}">forces the browser to save the file with the correct name, bypassing the PDF viewer's internal download logic.Since the file content is already fetched as a Blob (via
URL.createObjectURL) for the iframe preview, the download button reuses the same blob URL — no extra network request needed.Changes
ui/src/components/code-editor/view/subcomponents/CodeEditorBinaryFile.tsxuseBlobUrlcalled separately insideImagePreviewandPdfPreviewCodeEditorBinaryFile— single fetch, sharedblobUrlblobUrlis ready, next to fullscreen/close buttons<a download>with originalfile.nameTesting Notes