Skip to content
This repository has been archived by the owner on Mar 14, 2019. It is now read-only.

"Error: self.allowsFile is not a function" when sync-wrapping Collection.insert #1001

Open
lucnat opened this issue Apr 16, 2017 · 1 comment

Comments

@lucnat
Copy link

lucnat commented Apr 16, 2017

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.

@lucnat lucnat changed the title Error: self.allowsFile is not a function "Error: self.allowsFile is not a function" when sync-wrapping Collection.insert Apr 16, 2017
@DAB0mB
Copy link

DAB0mB commented Apr 20, 2017

You need to bind the insert function to the right context: Images. insert. bind(Images)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants