diff --git a/src/storage.js b/src/storage.js index f5141f9..08fbc79 100644 --- a/src/storage.js +++ b/src/storage.js @@ -113,12 +113,16 @@ function processUploaded(req, res, next) { // skipcq: JS-0045 .catch(reject) )) .then(() => log.debug('File saved', req.file.originalname, s3enabled ? 'in S3' : 'on disk')) - .then(() => !s3enabled && (req.file.path = getLocalFilename(req))) // skipcq: JS-0090 - .then(() => next()) .catch(next) - .finally(() => fs.remove(req.file.path)) + + // Delete the file + .then(() => fs.remove(req.file.path)) .then(() => log.debug('Temp file', 'deleted')) - .catch((err) => log.err(err)); + + // Fix the file path + .then(() => !s3enabled && (req.file.path = getLocalFilename(req))) // skipcq: JS-0090 + .then(() => next()) + .catch(next); } function deleteS3(file) {