Express middleware for reaping uploaded files saved to disk by multer or any multipart middleware propagating the req.files object. The middleware will automatically remove any uploaded files left in their temporary location upon response end or close.
$ npm install multer-autoreap
as app middleware
const express = ;const multer = ;const autoReap = ;let app = ;app;app;...
or attaching to a route / router.
const express = ;const router = express;const multer = ;const autoReap = ;let app = ;app;app;router;...
Multer is an efficient
multipart/form-data handling middleware that uses busboy. Files encoded in a miltipart request body are piped to a temporary upload location (def: multer options dest ). This can have the effect of leaving open an attack vector where disk space can be consumed by these temporary files. Its prudent and generally good form to clean them up. While reap cleans based on age, multer-autoreap cleans them up as soon as the request is done.
autoReapoptions =reapOnError: true;
- reapOnError (boolean) - If an error occurs, continue reaping the file, or no.
var autoReap = ;autoReapoptionsreapOnError = false;
The middleware will emit an 'autoreap' event on the Response object when removing files. The event will include the original file object from req.files.
Please report any issues...