Use saveURLAsFile
This commit is contained in:
parent
394d2f0bff
commit
21db2e7182
2 changed files with 6 additions and 4 deletions
|
@ -179,6 +179,7 @@
|
|||
saveFile() {
|
||||
Signal.Types.AttachmentTS.save({
|
||||
attachment: this.model,
|
||||
document,
|
||||
timestamp: this.timestamp,
|
||||
});
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue