diff --git a/lib/client/fileUpload.js b/lib/client/fileUpload.js index 7ffa745..aa19286 100644 --- a/lib/client/fileUpload.js +++ b/lib/client/fileUpload.js @@ -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; @@ -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; }; diff --git a/package.js b/package.js index 0fb31df..b11644a 100644 --- a/package.js +++ b/package.js @@ -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' }); @@ -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([