turns out it was deprecated... BRUH
This commit is contained in:
parent
1102ff0ef8
commit
1c1ab074ce
1 changed files with 5 additions and 3 deletions
8
index.js
8
index.js
|
@ -87,14 +87,16 @@ app.post('/api/upload', (req, res) => {
|
||||||
const file = req.files.file;
|
const file = req.files.file;
|
||||||
const filepath = `${config.storagePath}/${file.name}`;
|
const filepath = `${config.storagePath}/${file.name}`;
|
||||||
|
|
||||||
fs.exists(filepath, (exists) => {
|
fs.stat(filepath, (err) => {
|
||||||
if (!exists) {
|
if(err == null) {
|
||||||
|
return res.status(400).send('File exists.');
|
||||||
|
} else if(err.code === 'ENOENT') {
|
||||||
file.mv(filepath, (err) => {
|
file.mv(filepath, (err) => {
|
||||||
if (err) return res.status(500).send(err);
|
if (err) return res.status(500).send(err);
|
||||||
res.render('uploaded', { file: { name: file.name } });
|
res.render('uploaded', { file: { name: file.name } });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return res.status(400).send('File exists.');
|
return res.sendStatus(500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue