diff --git a/src/app/components/Pdf-viewer/PdfViewer.tsx b/src/app/components/Pdf-viewer/PdfViewer.tsx index 9c7fd9804..abb4d38ee 100644 --- a/src/app/components/Pdf-viewer/PdfViewer.tsx +++ b/src/app/components/Pdf-viewer/PdfViewer.tsx @@ -27,6 +27,7 @@ import { AsyncStatus } from '../../hooks/useAsyncCallback'; import { useZoom } from '../../hooks/useZoom'; import { createPage, usePdfDocumentLoader, usePdfJSLoader } from '../../plugins/pdfjs-dist'; import { stopPropagation } from '../../utils/keyboard'; +import { getSrcFile } from '../message/content/util'; export type PdfViewerProps = { name: string; @@ -78,7 +79,9 @@ export const PdfViewer = as<'div', PdfViewerProps>( }, [docState, pageNo, zoom]); const handleDownload = () => { - FileSaver.saveAs(src, name); + getSrcFile(src).then((blob) => { + FileSaver.saveAs(blob, name); + }); }; const handleJumpSubmit: FormEventHandler = (evt) => { diff --git a/src/app/components/image-viewer/ImageViewer.tsx b/src/app/components/image-viewer/ImageViewer.tsx index 4fd06b7a7..a2a5c8ca8 100644 --- a/src/app/components/image-viewer/ImageViewer.tsx +++ b/src/app/components/image-viewer/ImageViewer.tsx @@ -6,6 +6,7 @@ import { Box, Chip, Header, Icon, IconButton, Icons, Text, as } from 'folds'; import * as css from './ImageViewer.css'; import { useZoom } from '../../hooks/useZoom'; import { usePan } from '../../hooks/usePan'; +import { getSrcFile } from '../message/content/util'; export type ImageViewerProps = { alt: string; @@ -19,7 +20,9 @@ export const ImageViewer = as<'div', ImageViewerProps>( const { pan, cursor, onMouseDown } = usePan(zoom !== 1); const handleDownload = () => { - FileSaver.saveAs(src, alt); + getSrcFile(src).then((blob) => { + FileSaver.saveAs(blob, alt); + }); }; return ( diff --git a/src/app/components/message/content/FileContent.tsx b/src/app/components/message/content/FileContent.tsx index 379d14563..f08cdc438 100644 --- a/src/app/components/message/content/FileContent.tsx +++ b/src/app/components/message/content/FileContent.tsx @@ -176,7 +176,11 @@ export function ReadPdfFile({ body, mimeType, url, encInfo, renderViewer }: Read const [pdfState, loadPdf] = useAsyncCallback( useCallback(async () => { - const httpUrl = await getFileSrcUrl(mxcUrlToHttp(mx, url, useAuthentication) ?? '', mimeType, encInfo); + const httpUrl = await getFileSrcUrl( + mxcUrlToHttp(mx, url, useAuthentication) ?? '', + mimeType, + encInfo + ); setPdfViewer(true); return httpUrl; }, [mx, url, useAuthentication, mimeType, encInfo]) @@ -251,8 +255,13 @@ export function DownloadFile({ body, mimeType, url, info, encInfo }: DownloadFil const [downloadState, download] = useAsyncCallback( useCallback(async () => { - const httpUrl = await getFileSrcUrl(mxcUrlToHttp(mx, url, useAuthentication) ?? '', mimeType, encInfo); - FileSaver.saveAs(httpUrl, body); + const httpUrl = await getFileSrcUrl( + mxcUrlToHttp(mx, url, useAuthentication) ?? '', + mimeType, + encInfo + ); + const httpSrc = httpUrl.startsWith('blob') ? httpUrl : await getSrcFile(httpUrl); + FileSaver.saveAs(httpSrc, body); return httpUrl; }, [mx, url, useAuthentication, mimeType, encInfo, body]) );