From 21db2e71823a32c63d2805c26e253271569fe0b0 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Thu, 26 Apr 2018 16:42:10 -0400 Subject: [PATCH] Use `saveURLAsFile` --- js/views/attachment_view.js | 1 + ts/types/Attachment.ts | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/js/views/attachment_view.js b/js/views/attachment_view.js index 84d7fab35..ac6c4f49c 100644 --- a/js/views/attachment_view.js +++ b/js/views/attachment_view.js @@ -179,6 +179,7 @@ saveFile() { Signal.Types.AttachmentTS.save({ attachment: this.model, + document, timestamp: this.timestamp, }); }, diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index b71421557..770f1bcbd 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -5,6 +5,7 @@ import is from '@sindresorhus/is'; import moment from 'moment'; import * as GoogleChrome from '../util/GoogleChrome'; +import { saveURLAsFile } from '../util/saveURLAsFile'; import { arrayBufferToObjectURL } from '../util/arrayBufferToObjectURL'; import { MIMEType } from './MIME'; @@ -41,19 +42,19 @@ export const isVisualMedia = (attachment: Attachment): boolean => { export const save = ({ attachment, + document, timestamp, }: { attachment: Attachment; + document: Document; timestamp?: number; }): void => { const url = arrayBufferToObjectURL({ data: attachment.data, type: SAVE_CONTENT_TYPE, }); - const anchorElement = document.createElement('a'); - anchorElement.href = url; - anchorElement.download = getSuggestedFilename({ attachment, timestamp }); - anchorElement.click(); + const filename = getSuggestedFilename({ attachment, timestamp }); + saveURLAsFile({ url, filename, document }); URL.revokeObjectURL(url); };