Trying to upload an attachment with Meteor-Files

This commit is contained in:
Romulus Urakagi Tsai 2019-11-18 01:47:26 +00:00
parent 9fd14f7ecb
commit 05c53ca01d
8 changed files with 132 additions and 84 deletions

View file

@ -149,20 +149,28 @@ Template.previewClipboardImagePopup.events({
if (results && results.file) {
window.oPasted = pastedResults;
const card = this;
const file = new FS.File(results.file);
const settings = {
file: results.file,
streams: 'dynamic',
chunkSize: 'dynamic'
};
if (!results.name) {
// if no filename, it's from clipboard. then we give it a name, with ext name from MIME type
// FIXME: Check this behavior
if (typeof results.file.type === 'string') {
file.name(results.file.type.replace('image/', 'clipboard.'));
settings.fileName = new Date().getTime() + results.file.type.replace('.+/', '');
}
}
file.updatedAt(new Date());
file.boardId = card.boardId;
file.cardId = card._id;
file.userId = Meteor.userId();
const attachment = Attachments.insert(file);
settings.meta = {};
settings.meta.updatedAt = new Date().getTime();
settings.meta.boardId = card.boardId;
settings.meta.cardId = card._id;
settings.meta.userId = Meteor.userId();
console.log('settings', settings);
const attachment = Attachments.insert(settings, false);
if (attachment && attachment._id && attachment.isImage()) {
// TODO: Check image cover behavior
if (attachment && attachment._id && attachment.isImage) {
card.setCover(attachment._id);
}

View file

@ -34,21 +34,27 @@ Utils = {
if (!card) {
return next();
}
const file = new FS.File(fileObj);
let settings = {
file: fileObj,
streams: 'dynamic',
chunkSize: 'dynamic'
};
settings.meta = {};
if (card.isLinkedCard()) {
file.boardId = Cards.findOne(card.linkedId).boardId;
file.cardId = card.linkedId;
settings.meta.boardId = Cards.findOne(card.linkedId).boardId;
settings.meta.cardId = card.linkedId;
} else {
file.boardId = card.boardId;
file.swimlaneId = card.swimlaneId;
file.listId = card.listId;
file.cardId = card._id;
settings.meta.boardId = card.boardId;
settings.meta.swimlaneId = card.swimlaneId;
settings.meta.listId = card.listId;
settings.meta.cardId = card._id;
}
file.userId = Meteor.userId();
if (file.original) {
settings.meta.userId = Meteor.userId();
// FIXME: What is this?
/* if (file.original) {
file.original.name = fileObj.name;
}
return next(Attachments.insert(file));
}*/
return next(Attachments.insert(settings, false));
},
shrinkImage(options) {
// shrink image to certain size