Привет всем У меня проблемы с загрузкой нескольких изображений с помощью multer. Я использую базу данных MySQL для моего узла js application.here приведен код файла js ниже. Любой совет или исправление с вашей стороны будет высоко ценится
var multer = require('multer'); //for file uploading
var upload = multer({
dest: '/tmp/'
}); //for file uploading
const fileUpload = require('express-fileupload'); //for file uploading
app.use(fileUpload({
safeFileNames: true,
preserveExtension: true
})) //for file uploading
router.post('/wwasubmenuinsertion', upload.array('image'), (request, response) => {
if (request.file !== undefined) {
var background_image = request.file.originalname; //for file uploading
var file = 'public/whoweareuploads' + '/' + request.file.originalname; //for file uploading
fs.rename(request.file.path, file, function (err) {
console.log('success')
});
var data = {
wwa_sub_menu_title: request.body.title,
wwa_sub_menu_content: request.body.about,
wwa_sub_menu_background_image: background_image
}
mysqlconnection.query('INSERT INTO who_we_are set ?', data, (err, rows) => {
if (err) {
console.log(err);
} else {
response.redirect('/adminportal/wwasubmenulist');
}
});
}
});
А вот мой HTML-код
<form action="/adminportal/wwasubmenuinsertion" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="image">Sub Menu Name</label>
<input type="text" id="title" name="title" class="form-control">
</div>
<input name="about" type="hidden">
<div id="editor-container">
<p></p>
</div>
<br>
<div class="form-group">
<label for="image">Choose Background Image</label>
<input type="file" id="image" name="image" multiple>
</div>
<button class="btn btn-primary" type="submit" style="margin-top: 5px">Submit</button>
</form>