Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { testAttachment } from './utils';
requireContext();

async function uploadFileMock(): Promise<SpecifyResource<Attachment>> {
return deserializeResource(testAttachment) ;
return deserializeResource(testAttachment);
}

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,13 @@ export function downloadAttachment(
const fileName = cleanAttachmentDownloadName(
attachment.origFilename ?? attachment.attachmentLocation
);
downloadFile(
fileName,
`/attachment_gw/proxy/${new URL(url).search}`,
true
);
// Cannot use downloadFile because of iframe restrictions
const element = document.createElement('a');
element.href = `/attachment_gw/proxy/${new URL(url).search}`;
element.download = fileName;
document.body.append(element);
element.click();
element.remove();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ export function FilePicker({
*/
export const downloadFile = async (
fileName: string,
data: Blob | string,
isUrl?: boolean
data: Blob | string
): Promise<void> =>
new Promise((resolve) => {
let fileDownloaded = false;
Expand All @@ -148,10 +147,7 @@ export const downloadFile = async (
if (iframe.contentWindow === null || fileDownloaded) return;
let dataUrl: string | undefined;
const element = iframe.contentWindow.document.createElement('a');
if (isUrl === true) {
element.setAttribute('href', data as string);
element.setAttribute('download', fileName);
} else if (typeof data === 'string') {
if (typeof data === 'string') {
element.setAttribute(
'href',
`data:text/plain;charset=utf-8,${encodeURIComponent(data)}`
Expand Down