add check for files that already exist
This commit is contained in:
parent
ce8c86f6da
commit
73491c9387
1 changed files with 10 additions and 3 deletions
9
index.js
9
index.js
|
@ -85,11 +85,18 @@ app.post('/api/upload', (req, res) => {
|
|||
}
|
||||
|
||||
const file = req.files.file;
|
||||
const filepath = `${config.storagePath}/${file.name}`;
|
||||
|
||||
file.mv(`${config.storagePath}/${file.name}`, function(err) {
|
||||
path.exists(filepath, (exists) => {
|
||||
if (!exists) {
|
||||
file.mv(filepath, (err) => {
|
||||
if (err) return res.status(500).send(err);
|
||||
res.render('uploaded', { file: { name: file.name } });
|
||||
});
|
||||
} else {
|
||||
return res.status(400).send('File exists.');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(config.server.port);
|
Loading…
Reference in a new issue