multipart: cleanup files after reading their contents
one idea is just use express.raw() . however, we have to implement some file size limit there. one case this does not handle is aborted uploads from a box.service restart. for this rare case, a server reboot will clean up /tmp anyway.
This commit is contained in:
@@ -128,6 +128,7 @@ async function setAvatar(req, res, next) {
|
||||
|
||||
if (req.files && req.files.avatar) {
|
||||
avatar = safe.fs.readFileSync(req.files.avatar.path);
|
||||
safe.fs.unlinkSync(req.files.avatar.path);
|
||||
if (!avatar) return next(BoxError.toHttpError(new BoxError(BoxError.FS_ERROR, safe.error.message)));
|
||||
} else if (!avatar || (!avatar.equals(constants.AVATAR_GRAVATAR) && !avatar.equals(constants.AVATAR_NONE))) {
|
||||
return next(new HttpError(400, `avatar must be a file, ${constants.AVATAR_GRAVATAR} or ${constants.AVATAR_NONE}`));
|
||||
@@ -176,6 +177,7 @@ async function setBackgroundImage(req, res, next) {
|
||||
|
||||
if (req.files && req.files.backgroundImage) {
|
||||
backgroundImage = safe.fs.readFileSync(req.files.backgroundImage.path);
|
||||
safe.fs.unlinkSync(req.files.backgroundImage.path);
|
||||
if (!backgroundImage) return next(BoxError.toHttpError(new BoxError(BoxError.FS_ERROR, safe.error.message)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user