[英]Receiving multiple images using multer in NodeJS problem
我正在使用 multer package 從前端(ReactJS)接收多個圖像。除了基本字段之外,我還發送了一組圖像,我想將它們保存在我的 Rest ZDB974238714CA8DE4F638 服務器中我正在接收我的身體字段,但問題是沒有收到圖像。 這是我的代碼:
const multer = require('multer');
const storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, './uploads/');
},
filename: function(req, file, cb) {
cb(null, new Date().toISOString() + file.originalname);
}
});
const fileFilter = (req, file, cb) => {
if(file.mimetype === 'image/jpeg' || file.mimetype === 'image/png'){
cb(null, true);
} else {
cb(new Error('worng file format'), true);
}
}
// initialize multer
const upload = multer(
{
storage: storage,
fileFilter: fileFilter,
}
);
router.get('/', categoryController.getCategories);
router.post('/', upload.array('images', 3), (req, res, next) => {
try {
// here I want the images to save their location
console.log(req.files);
const name = req.body.name;
const description = req.body.description;
} catch (err) {
}
});
我的圖像應該在的文件夾upload
是空的; 那么,如何保存我的多個圖像?
Append 每個文件單獨成表格:
for (const file of selectedFiles) {
formData.append('image', file);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.