From d9dac00a018ae474593ca9b0a41f7f263ce49bdc Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 17 Nov 2022 22:54:45 +0100 Subject: [PATCH] add TRILIUM_NO_UPLOAD_LIMIT to disable the upload limit, #3164 --- src/routes/routes.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/routes/routes.js b/src/routes/routes.js index 5df0c9b0b..2342dedb2 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -197,17 +197,23 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio const MAX_ALLOWED_FILE_SIZE_MB = 250; const GET = 'get', POST = 'post', PUT = 'put', PATCH = 'patch', DELETE = 'delete'; -const uploadMiddleware = multer({ + +const multerOptions = { fileFilter: (req, file, cb) => { // UTF-8 file names are not well decoded by multer/busboy, so we handle the conversion on our side. // See https://github.com/expressjs/multer/pull/1102. file.originalname = Buffer.from(file.originalname, "latin1").toString("utf-8"); cb(null, true); - }, - limits: { - fileSize: MAX_ALLOWED_FILE_SIZE_MB * 1024 * 1024 } -}).single('upload'); +}; + +if (!process.env.TRILIUM_NO_UPLOAD_LIMIT) { + multerOptions.limits = { + fileSize: MAX_ALLOWED_FILE_SIZE_MB * 1024 * 1024 + }; +} + +const uploadMiddleware = multer(multerOptions).single('upload'); const uploadMiddlewareWithErrorHandling = function (req, res, next) { uploadMiddleware(req, res, function (err) {