Самый простой способ - просто сохранить URL-адрес изображения в этой функции:
form.on('file', function (name, file){
console.log('Uploaded ' + file.name);
});
В зависимости от того, как вы подключаетесь к базе данных, синтаксис должен выглядеть примерно так:
form.on('file', function (name, file){
database.find({file: file.path}, (err, result) => {
// Throw error if find function fails
if(err) return(new Error(err));
// Throw error if there is already a file with that name
if(result) return(new Error('File with that name already exists, please choose another name'));
database.save({file: file.path}, (err, result) => {
// Throw error if save function fails
if(err) return(new Error(err));
// Throw error if you cannot verifty the save occured.
if(result.count !== 1) return(new Error('There was an unexpected error. Please try again'));
// Send Log to signal successfull upload
console.log('Uploaded ' + file.name);
});
});
});
РЕДАКТИРОВАТЬ # 1:
В MySQL это выглядело бы примерно так:
form.on('file', function (name, file){
connection.query('SQL SELECT QUERY HERE', (err, results) => {
// Throw error if find function fails
if(err) return(new Error(err));
// Throw error if there is already a file with that name
if(results[0]) return(new Error('File with that name already exists, please choose another name'));
connection.query('SQL INSERT QUERY HERE', (error, results) => {
// Throw error if save function fails
if(err) return(new Error(err));
// Throw error if you cannot verifty the save occured.
if(results.affectedRows !== 1) return(new Error('There was an unexpected error. Please try again'));
// Send Log to signal successfull upload
console.log('Uploaded ' + file.name);
});
});
});