Meteor-CollectionFS
Meteor-CollectionFS copied to clipboard
"Error: self.allowsFile is not a function" when sync-wrapping Collection.insert
I have an Images
collection with an S3 store. I would like to have a sync insert on the server. I need this because it is inside an API endpoint which has to give the response only when the insert is done and the cfs endpoints are ready. I tried this:
var synchedInsert = Meteor.wrapAsync(Images.insert); // make an sync version of the insert
var fileObj = synchedInsert(this.request.body.data)
The synchedInsert() throws this error:
W20170416-20:19:02.757(2)? (STDERR) TypeError: self.allowsFile is not a function
W20170416-20:19:02.758(2)? (STDERR) at checkAndInsert (packages/cfs_collection.js:254:15)
W20170416-20:19:02.758(2)? (STDERR) at attachDataCallback (packages/cfs_collection.js:298:11)
W20170416-20:19:02.759(2)? (STDERR) at setName (packages/cfs_file.js:179:17)
W20170416-20:19:02.760(2)? (STDERR) at setData (packages/cfs_file.js:159:7)
W20170416-20:19:02.760(2)? (STDERR) at EventEmitter.fsFileAttachData [as attachData] (packages/cfs_file.js:130:5)
W20170416-20:19:02.761(2)? (STDERR) at FS.Collection.insert (packages/cfs_collection.js:294:15)
W20170416-20:19:02.761(2)? (STDERR) at packages/meteor.js:212:23
W20170416-20:19:02.762(2)? (STDERR) at Object.ApiV1.addRoute.post [as action] (server/apiv1/photos.js:6:23)
W20170416-20:19:02.762(2)? (STDERR) at Route.share.Route.Route._callEndpoint (packages/nimble_restivus/lib/route.coffee:150:32)
W20170416-20:19:02.762(2)? (STDERR) at packages/nimble_restivus/lib/route.coffee:59:33
Any suggestions on how to sync insert? FYI the collection has three S3 stores with transformWrite() to three different sizes. Why can't we wrap the callback of Images.insert
using Meteor.wrapAsync
? I have also used meteorhacks:async
which gives the same error.
You need to bind the insert function to the right context: Images. insert. bind(Images)