node.js - 无法获取 req.files。React-native - Node js (multer)
问题描述
我正在尝试创建上传图片过程。我需要上传一组图片。
在我的客户上:
const data = new FormData();
pictures.forEach(pic => {
data.append('pictures', {
fileName: pic.fileName,
uri: pic.image,
type: pic.type,
});
});
const headers = {
'Content-Type': 'multipart/form-data',
'x-access-token': token,
};
const diaryUpdatePost = await post(`diary/uploadPictures/${diary}`, pictures, {
headers,
});
在服务器端,我的路由器使用 upload.array (multer) 中间件:
const upload = multer({
dest: 'uploads/',
limits: { fieldSize: 25 * 1024 * 1024 },
rename(fieldname, filename) {
return filename;
},
});
router.post('/uploadPictures/:name', upload.array('pictures'), diaryController.uploadDiaryPictures);
最后是问题:
在 diaryController.uploadDiaryPictures 我的 req.files 日志未定义。我做错了什么?
exports.uploadDiaryPictures = async (req, res) => {
//Logs undefined
global.logger.info(`Updating diary pictures ${req.files}...`);
};
解决方案
推荐阅读
- asp.net - 使用 Umbraco 重写时如何删除查询字符串
- ruby - 将整个数组重新分配给相同的引用
- javascript - 创建颜色明智的多行粒子
- javascript - 从 React 的返回方法中的数组中删除元素
- google-apps-script - replacetext 反斜杠括号不起作用
- java - 跟踪过去 15 分钟内的触摸事件数
- android - 中文设备上的 WebView 忽略强制设置的视图大小
- javascript - 我对嵌套查找的 mongodb 聚合函数有问题
- flutter - 即使在删除 Permission Handler Plugin 后,Flutter App 仍在请求权限
- python-3.x - python3中的嵌套循环