From 6e1dce94f030612d966bdc42446878050d338784 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sun, 13 Sep 2020 23:03:20 -0500 Subject: [PATCH] Ref: attachment image paste --- client/components/cards/attachments.js | 42 ++++++++++++++------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/client/components/cards/attachments.js b/client/components/cards/attachments.js index a867b74fe..96255fc40 100644 --- a/client/components/cards/attachments.js +++ b/client/components/cards/attachments.js @@ -127,26 +127,30 @@ Template.previewClipboardImagePopup.events({ if (results && results.file) { window.oPasted = pastedResults; const card = this; - const file = new FS.File(results.file); - if (!results.name) { - // if no filename, it's from clipboard. then we give it a name, with ext name from MIME type - if (typeof results.file.type === 'string') { - file.name(results.file.type.replace('image/', 'clipboard.')); + const uploader = Attachments.insert( + { + file: results.file, + fileName: + results.name || results.file.type.replace('image/', 'clipboard.'), + streams: 'dynamic', + chunkSize: 'dynamic', + }, + false, + ); + uploader.on('uploaded', (error, fileObj) => { + if (!error) { + if (fileObj.isImage) { + card.setCover(fileObj._id); + } + Utils.addCommonMetaToAttachment(card, fileObj); } - } - file.updatedAt(new Date()); - file.boardId = card.boardId; - file.cardId = card._id; - file.userId = Meteor.userId(); - const attachment = Attachments.insert(file); - - if (attachment && attachment._id && attachment.isImage()) { - card.setCover(attachment._id); - } - - pastedResults = null; - $(document.body).pasteImageReader(() => {}); - Popup.close(); + }); + uploader.on('end', (error, fileObj) => { + pastedResults = null; + $(document.body).pasteImageReader(() => {}); + Popup.close(); + }); + uploader.start(); } }, });