madhums / node-express-mongoose-demo

A simple demo app using node and mongodb for beginners (with docker)
https://nodejs-express-demo.fly.dev
MIT License
5.12k stars 1.38k forks source link

removing old images on *article* update #129

Closed fyyyyy closed 5 years ago

fyyyyy commented 9 years ago

I'm not sure how this is supposed to work, however when updating an article by re-uploading the image, the old image does not get removed from S3. I guess article.js is missing a pre('update') similar to the remove hook, but only if req.files.image===true ?

ArticleSchema.pre('remove', function (next) {
  var imager = new Imager(imagerConfig, 'S3');
  var files = this.image.files;

  // if there are files associated with the item, remove from the cloud too
  imager.remove(files, function (err) {
    if (err) return next(err);
  }, 'article');

  next();
});
madhums commented 5 years ago

I've removed the image uploading functionality as I don't own a aws account. Closing as it is not relevant for the current code right now.