Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: download document from link
Marc Seitz9c83223912ec
diff --git a/components/view/dataroom/document-card.tsx b/components/view/dataroom/document-card.tsxindex eb616d18..675b7331 100644--- a/components/view/dataroom/document-card.tsx+++ b/components/view/dataroom/document-card.tsx@@ -8,7 +8,6 @@ import { toast } from "sonner";import { timeAgo } from "@/lib/utils";import { cn } from "@/lib/utils";-import { triggerBlobDownload } from "@/lib/utils/trigger-download";import { fileIcon } from "@/lib/utils/get-file-icon";import {HIERARCHICAL_DISPLAY_STYLE,@@ -152,14 +151,20 @@ export default function DocumentCard({return "File downloaded successfully";}- // For all other files, fetch as blob for reliable cross-browser download+ // For all other files, use a hidden iframe to trigger the downloadif (contentType?.includes("application/json")) {const data = await response.json();- await triggerBlobDownload(- data.downloadUrl,- data.fileName || document.name,- );+ const iframe = window.document.createElement("iframe");+ iframe.style.display = "none";+ window.document.body.appendChild(iframe);+ iframe.src = data.downloadUrl;++ setTimeout(() => {+ if (iframe.parentNode) {+ window.document.body.removeChild(iframe);+ }+ }, 5000);return "File downloaded successfully";}diff --git a/components/view/nav.tsx b/components/view/nav.tsxindex 5c068e91..fbbeea9e 100644--- a/components/view/nav.tsx+++ b/components/view/nav.tsx@@ -18,7 +18,6 @@ import {import { toast } from "sonner";import { determineTextColor } from "@/lib/utils/determine-text-color";-import { triggerBlobDownload } from "@/lib/utils/trigger-download";import {DropdownMenu,@@ -180,12 +179,18 @@ export default function Nav({}, 100);} else {// Handle JSON response with downloadUrl (non-watermarked files)- const { downloadUrl, fileName } = await response.json();+ const { downloadUrl } = await response.json();- await triggerBlobDownload(- downloadUrl,- fileName || "document",- );+ const iframe = document.createElement("iframe");+ iframe.style.display = "none";+ document.body.appendChild(iframe);+ iframe.src = downloadUrl;++ setTimeout(() => {+ if (iframe.parentNode) {+ document.body.removeChild(iframe);+ }+ }, 5000);}return "File downloaded successfully";diff --git a/components/view/viewer/download-only-viewer.tsx b/components/view/viewer/download-only-viewer.tsxindex 42163837..042ef674 100644--- a/components/view/viewer/download-only-viewer.tsx+++ b/components/view/viewer/download-only-viewer.tsx@@ -7,7 +7,6 @@ import { toast } from "sonner";import { useSafePageViewTracker } from "@/lib/tracking/safe-page-view-tracker";import { getTrackingOptions } from "@/lib/tracking/tracking-config";-import { triggerBlobDownload } from "@/lib/utils/trigger-download";import { Button } from "@/components/ui/button";@@ -234,12 +233,18 @@ export default function DownloadOnlyViewer({}, 100);} else {// Handle JSON response with downloadUrl (non-watermarked files)- const { downloadUrl, fileName } = await response.json();+ const { downloadUrl } = await response.json();- await triggerBlobDownload(- downloadUrl,- fileName || documentName || "document",- );+ const iframe = document.createElement("iframe");+ iframe.style.display = "none";+ document.body.appendChild(iframe);+ iframe.src = downloadUrl;++ setTimeout(() => {+ if (iframe.parentNode) {+ document.body.removeChild(iframe);+ }+ }, 5000);}return "File downloaded successfully";diff --git a/lib/utils/trigger-download.ts b/lib/utils/trigger-download.tsdeleted file mode 100644index 70fcd1dd..00000000--- a/lib/utils/trigger-download.ts+++ /dev/null@@ -1,40 +0,0 @@-/**- * Triggers a reliable file download that works across all browsers,- * including iOS Safari, Chrome, and Brave.- *- * The standard approach of creating an <a> element and calling click()- * with a cross-origin URL fails on many browsers (especially mobile)- * because:- * 1. The `download` attribute is ignored for cross-origin URLs- * 2. `window.open()` is blocked by popup blockers in async callbacks- * 3. iOS WebKit requires user activation for navigation, which expires- * after an async operation like fetch()- *- * This utility fetches the file as a blob and creates a same-origin- * blob URL, which always respects the `download` attribute.- */-export async function triggerBlobDownload(- url: string,- fileName: string,-): Promise<void> {- const response = await fetch(url);-- if (!response.ok) {- throw new Error(`Failed to fetch file: ${response.statusText}`);- }-- const blob = await response.blob();- const blobUrl = URL.createObjectURL(blob);-- const link = document.createElement("a");- link.href = blobUrl;- link.download = fileName;- link.rel = "noopener noreferrer";- document.body.appendChild(link);- link.click();-- setTimeout(() => {- URL.revokeObjectURL(blobUrl);- document.body.removeChild(link);- }, 100);-}