var getFilename = new Promise(<b>partFilename</b>, (resolve, reject) => {
var files = fs.readdirSync(uploadPath);
files.forEach(file => {
var comparedPart = file.split('.')[0];
if (comparedPart == partFilename) {
resolve(file);
}
});
reject(new Error('404'));
});
router.get('/:id', function(req, res, next) {
var partFilename = req.params.id;
getFilename(<b>fileName</b>)
.then(
result => {
res.download(uploadPath + result, result, function(err) {
if (err) {
console.log(err);
}
});
},
error => {
res.send(error.message);
}
);
});
var getFilename = function (partFilename) {
return new Promise((resolve, reject) => {
var files = fs.readdirSync(uploadPath);
files.forEach(file => {
var comparedPart = file.split('.')[0];
if (comparedPart == partFilename) {
resolve(file);
}
});
reject(new Error('404'));
});
}
var getFilename = function (partFilename) {
return new Promise((resolve, reject) => {
var files = fs.readdir(uploadPath, (err, files) => {
if (err) {
reject(new Error('404'));
} else {
files.forEach(file => {
var comparedPart = file.split('.')[0];
if (comparedPart == partFilename) {
resolve(file);
}
});
}
})
});
}