From a592adf834c955f5a423dfeccf6034868d49c3fd Mon Sep 17 00:00:00 2001 From: daniel-j Date: Wed, 4 Mar 2020 13:41:38 +0100 Subject: [PATCH] delete old file if existing --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index 9b19236..cb69bb0 100644 --- a/index.js +++ b/index.js @@ -178,6 +178,12 @@ router.post('/upload', upload.single('file'), async ctx => { expireKey(key) const info = ctx.keys.get(key) + if (info.file && info.file.path) { + await new Promise((resolve, reject) => fs.unlink(info.file.path, (err) => { + if (err) reject(err) + resolve() + })) + } info.file = { name: filename, path: data,