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:
Girish Ramakrishnan
2024-07-19 23:11:26 +02:00
parent 7f11699fac
commit c85c0558b9
4 changed files with 14 additions and 6 deletions
+2
View File
@@ -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)));
}