-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Object { _id: 5219f3858ec1ba1c28000001 } has no method 'attach' #31
Comments
Could you please post the code where you are initalizing and attaching mongoose-attachments? Please make sure that you use the documentation of the stable version https://github.com/heapsource/mongoose-attachments/tree/v0.0.4 . |
Hi, I face the same problem today. Here is my model config: AttachmentSchema.plugin(attachments, {
directory: '/app/uploads/startups/logos',
storage : {
providerName: 'localfs'
},
properties: {
image: {
styles: {
original: {
// keep the original file
},
thumb: {
thumbnail: '100x100^',
gravity: 'center',
extent: '100x100',
'$format': 'jpg'
},
detail: {
resize: '400x400>',
'$format': 'jpg'
}
}
}
}
});
module.exports = mongoose.model('Attachment', AttachmentSchema); And in controller: var attachment = new Attachment();
attachment.attach('image', req.files.file, function (err) {
if (err) {
return next(err);
}
attachment.save(function (err, attachment) {
if (err) {
res.status = 422;
res.json({success: false});
}
res.json({success: true, attachment: attachment});
});
}); |
After debugging, I realized that the I solved the problem by directly require the |
Hi vinh0604, Could you please paste the code for your solution? |
Thanks for your comment. It made me realize that the tag 0.1.0 is too old. The master version (untagged) of |
Will you be tagging a new version to correct the problem or should we use the master version? |
As a workaround:
should work. |
@henrynok |
Fixed in current master of |
I think it would be really important to release this fix as I just spent 2 hours tracking down this problem. Sure, part of it was because I'm new to MongooseJS and wasn't sure if I was doing something wrong but still... Or perhaps at least a README note? The workaround wasn't working for me, but changing my package.json to:
...did fix it. |
Hi I am new to mongoose-attachments. When I try the example I get a TypeError: Object { _id: 5219f3858ec1ba1c28000001 } has no method 'attach' .
I have tried everything please advise if I am doing anything wrong. I use the latest versions of Mongoosejs, Node and Express.
I tried to use it with all providers but no luck.
The text was updated successfully, but these errors were encountered: