You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var bcrypt = require('bcrypt-nodejs');
var Pictoose = require('pictoose');
// Must label separate db connections to prevent connection conflicts
var conn3 = mongoose.createConnection('localhost:27017/user');
var userSchema = new Schema({
email: {type: String, required: true},
{...edited for brevity...}
userImage1: {data: Buffer, contentType: String, required: false},
userImage2: {data: Buffer, contentType: String, required: false},
userImage3: {type: Buffer, required: false},
});
userSchema.methods.encryptPassword = function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(10), null);
};
userSchema.methods.validPassword = function(password) {
return bcrypt.compareSync(password, this.password);
};
userSchema.plugin(Pictoose.Plugin, ['userImage1','userImage2','userImage3']);
module.exports = conn3.model('User', userSchema);
routes/user.js
var express = require('express');
var router = express.Router();
var csrf = require('csurf');
{...unnecessary libraries edited out...}
var User = require('../models/user');
var multer = require('multer');
var Pictoose = require('pictoose');
// Config for Pictoose -- storing images in MongoDB via Mongoose
Pictoose.Config('RESOURCE_STORAGE_ROOT', './uploads/');
Pictoose.Config('RESOURCE_STORAGE_URL', 'http://127.0.0.1:3000/user/');
Pictoose.Config('RESOURCE_MAIN_URL', 'http://127.0.0.1:3000/resources/');
router.use('/user',express.static('./uploads'));
router.get('/resources/:resid', Pictoose.RouteController);
// Registration - Upload ID
router.get('/upload-id', ensureLoggedIn('/user/signin'), function(req, res) {
res.render('user/create/upload-id', { csrfToken: req.csrfToken() });
});
router.post('/upload-id', function(req, res) {
var token = req.user.verifyAccountToken;
if (!req.user) {
req.flash('error', 'The link you followed is no longer valid.');
return res.redirect('/user/signin');
}
// store images
try {
user.userImage1.data = fs.readFileSync(req.files.userImage1.path);
user.userImage1.contentType = 'image/png';
user.userImage2.data = fs.readFileSync(req.files.userImage2.path);
user.userImage3.contentType = 'image/png';
user.userImage3.data = fs.readFileSync(req.files.userImage3.path);
user.userImage.contentType = 'image/png';
user.save(function (err, a) {
if (err) throw err;
res.redirect('/user/profile');
});
} catch (err) {
req.flash('error', err);
res.redirect('/user/signup');
}
res.redirect('/user/profile');
});
The error I'm seeing:
D:\Desktop\website\node_modules\pictoose\pictoose.js:298
schema.virtual(fields[i]).get(PictureGetter(fields[i]));
^
TypeError: schema.virtual(...).get is not a function
at Plugin (D:\Desktop\website\node_modules\pictoose\pictoose.js:298:29)
at Schema.plugin (D:\Desktop\website\node_modules\mongoose\lib\schema.js:1162:3)
Hi -- I'm having some trouble getting this to work. My project structure:
app.js
models/ (mongoose models)
--user.js
routes/ (expressjs routes)
--user.js
models/user.js:
routes/user.js
The error I'm seeing:
The error seems to be caused by this line:
I've tried a few variants based on the documentation, but none seem to work. Any suggestions on what I'm doing wrong? Thanks!
The text was updated successfully, but these errors were encountered: