SHARE
TWEET

Untitled

a guest Jun 18th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const pictureSchema = new mongoose.Schema({
  2.     title: {type: String, maxlength: [50, 'Title must be longer than 50 characters']},
  3.     description: {type: String},
  4.     filename: {type: String},
  5.     thumbname:{type: String},
  6.     thumbswitch:{type: Boolean, default: false},
  7.     user: {type: mongoose.Schema.Types.ObjectId}
  8. });
  9.  
  10. var picture = mongoose.model('Picture', pictureSchema);
  11.  
  12. exports.picture = picture;
  13.      
  14. pics.post('/upload', (req, res) => {
  15.     upload.single('image')(req, res, (err) => {
  16.       if(err){
  17.         return res.status(500).json({ message: err });
  18.       } else {
  19.         if(req.file == undefined){
  20.             return res.status(500).json({ message: 'upload a valid file!' });
  21.         } else {
  22.           let pic = new picture({
  23.             title: req.body.title,
  24.             description: req.body.description,
  25.             filename: req.body.databasepicname,
  26.             user: mongoose.Types.ObjectId(req.user._id)
  27.           });
  28.           pic.save()
  29.           .then(() => res.status(201).json({ message: pic }))
  30.           .then(() => gm(path.resolve('./storage/media/' + req.body.databasepicname))      //// TODO: establish correct routes,
  31.           .resize(120, null)
  32.             .write(path.resolve('./storage/media/thumb' + '-' + req.body.databasepicname), function (err) {
  33.               if (!err) {
  34.                 console.log('thumbnail created successfully')
  35.                 pic.update($set{thumbname: 'thumb' + '-' + req.body.databasepicname,
  36.                             thumbswitch: true})
  37.                 pic.save().then(() => console.log(pic))
  38.                 }
  39.               else{console.log(err)}
  40.             })
  41.           )
  42.           };
  43.         }
  44.       });
  45.   });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top