Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const pictureSchema = new mongoose.Schema({
- title: {type: String, maxlength: [50, 'Title must be longer than 50 characters']},
- description: {type: String},
- filename: {type: String},
- thumbname:{type: String},
- thumbswitch:{type: Boolean, default: false},
- user: {type: mongoose.Schema.Types.ObjectId}
- });
- var picture = mongoose.model('Picture', pictureSchema);
- exports.picture = picture;
- pics.post('/upload', (req, res) => {
- upload.single('image')(req, res, (err) => {
- if(err){
- return res.status(500).json({ message: err });
- } else {
- if(req.file == undefined){
- return res.status(500).json({ message: 'upload a valid file!' });
- } else {
- let pic = new picture({
- title: req.body.title,
- description: req.body.description,
- filename: req.body.databasepicname,
- user: mongoose.Types.ObjectId(req.user._id)
- });
- pic.save()
- .then(() => res.status(201).json({ message: pic }))
- .then(() => gm(path.resolve('./storage/media/' + req.body.databasepicname)) //// TODO: establish correct routes,
- .resize(120, null)
- .write(path.resolve('./storage/media/thumb' + '-' + req.body.databasepicname), function (err) {
- if (!err) {
- console.log('thumbnail created successfully')
- pic.update($set{thumbname: 'thumb' + '-' + req.body.databasepicname,
- thumbswitch: true})
- pic.save().then(() => console.log(pic))
- }
- else{console.log(err)}
- })
- )
- };
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement