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
35 changes: 25 additions & 10 deletions lib/client/fileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,32 @@ Template.afFileUpload.onCreated(function () {
};
}

const mongoCollection = Mongo.Collection.get
? Mongo.Collection.get(this.data.atts.collection)
: Meteor.connection._mongo_livedata_collections[this.data.atts.collection]
// primary method: use dburles:mongo-collection-instances
if (Mongo.Collection.get) {
const mongoCollection = Mongo.Collection.get(this.data.atts.collection);
this.collection = mongoCollection && mongoCollection.filesCollection;
}

// 1. fallback using global scope
if (!this.collection) {
this.collection = global[this.data.atts.collection];
}

// 2. fallback using Meteor.connection / local collections
// if the Meteor release is newer than 2016 -> use _stores
// else use older _mongo_livedata_collections
// see https://github.com/meteor/meteor/pull/5845
if (!this.collection) {
const storedCollection = Meteor.connection._stores[this.data.atts.collection];
this.collection = (storedCollection && storedCollection._getCollection)
? storedCollection._getCollection().filesCollection
: Meteor.connection._mongo_livedata_collections[this.data.atts.collection];
}

this.collection = mongoCollection
? mongoCollection.filesCollection
: global[this.data.atts.collection]
if (!this.collection) {
throw new Meteor.Error(404, `[meteor-autoform-files] No collection found by name "${this.data.atts.collection}"`,
`Collection's name is case-sensetive. Please, make sure you're using right collection name.`);
}

this.uploadTemplate = this.data.atts.uploadTemplate || null;
this.previewTemplate = this.data.atts.previewTemplate || null;
Expand All @@ -43,10 +62,6 @@ Template.afFileUpload.onCreated(function () {
this.insertConfig.chunkSize = parseInt(this.insertConfig.chunkSize);
}

if (!this.collection) {
throw new Meteor.Error(404, '[meteor-autoform-files] No such collection "' + this.data.atts.collection + '"');
}

this.collectionName = function () {
return self.data.atts.collection;
};
Expand Down
4 changes: 2 additions & 2 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package.describe({
name: 'ostrio:autoform-files',
summary: 'File upload for AutoForm using ostrio:files',
description: 'File upload for AutoForm using ostrio:files',
version: '2.1.2',
version: '2.1.3',
git: 'https://github.com/VeliovGroup/meteor-autoform-file.git'
});

Expand All @@ -17,7 +17,7 @@ Package.onUse(function(api) {
'reactive-var',
'templating@1.3.2',
'aldeed:autoform@6.3.0',
'ostrio:files@1.10.1'
'ostrio:files@1.10.2'
]);

api.addFiles([
Expand Down