Я получаю ошибку:
Ошибка: нет такого файла или каталога, lstat '/public/userPosts/1583326108549.jpg
Я получаю каталог и Я не могу найти, почему это происходит. Я использую пакет image-watermark
async function createPost(req, res) {
upload(req, res, async function (err) {
if (req.fileValidationError) {
res.status(400).json({message: 'error', data: req.fileValidationError});
} else {
if (req.body.type == 'text') {
try {
req.body.userId = req.user._id;
await new postModel(req.body).save();
res.status(200).json({message: 'Post Created SuccessFully', data: []});
} catch (error) {
res.status(500).json({message: 'Error', data: [error]});
}
} else {
//console.log(req.files);
if (req.files.length > 0) {
try {
let fileNames = [];
let orgNames = [];
let imageNames = [];
req.body.userId = req.user._id;
for (let index = 0; index < req.files.length; index++) {
orgNames.push(imagePaths.profileImage + '/userPosts/' + req.files[index].filename);
imageNames.push(req.files[index].filename);
if (req.body.type === 'photo') { /* fileNames.push(imagePaths.profileImage + '/userPosts/processedImages/' + req.files[index].filename);*/
fileNames.push(imagePaths.profileImage + '/userPosts/' + req.files[index].filename);
console.log(imagePaths.profileImage);
var options = {
'text': req.body.companyName,
'color': 'rgb(154, 50, 46)',
'resize': '70%',
'dstPath': '../../public/userPosts/processedImages/' + req.files[index].filename
};
try {
await watermark.embedWatermark('/public/userPosts/'+req.files[index].filename, options, function (err) {
if (!err)
console.log('Succefully embeded watermark');
else {
console.log(err);
}
});
} catch (error) {
console.log(error);
res.status(500).json({ message: 'Error', data: [error] });
}
} else {
fileNames.push(imagePaths.profileImage + '/userPosts/' + req.files[index].filename);
}
}
try {
req.body.filename = fileNames;
req.body.Orgfilename = orgNames;
req.body.imageName = imageNames;
// console.log();
await new postModel(req.body).save();
res.status(200).json({message: 'Post Created SuccessFully', data: []});
} catch (error) {
console.log(error);
res.status(500).json({message: 'Error', data: [error]});
}
} catch (error) {
console.log(error);
res.status(500).json({message: 'Error', data: [error]});
}
} else {
res.status(400).json({message: 'No Files.', data: []});
}
}
}
});
}
Изображение успешно загружено, но я получаю сообщение об ошибке в разделе водяных знаков.