Skip to content

feat: add download button to PDF/image preview header#206

Open
tiger0425 wants to merge 1 commit into
OpenBMB:mainfrom
tiger0425:fix/pdf-preview-download-button
Open

feat: add download button to PDF/image preview header#206
tiger0425 wants to merge 1 commit into
OpenBMB:mainfrom
tiger0425:fix/pdf-preview-download-button

Conversation

@tiger0425

Copy link
Copy Markdown

Problem

When users preview a PDF file in the code editor, Chrome's embedded PDF viewer ignores the Content-Disposition header 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 filename parameter 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.tsx

Before After
useBlobUrl called separately inside ImagePreview and PdfPreview Hook hoisted to parent CodeEditorBinaryFile — single fetch, shared blobUrl
No download button in header Download icon appears when blobUrl is ready, next to fullscreen/close buttons
Header only had fullscreen + close New download button using <a download> with original file.name

Testing Notes

  • Open any PDF or image file in the code editor preview
  • Click the new download icon in the header
  • Verify the downloaded file keeps the original filename
  • Verify existing preview functionality is unchanged

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant