javascript - express js multer upload.single 不工作
问题描述
Multer 上传文件正常,但突然相同的代码没有在请求中获取文件对象。就像 multer 被完全忽略了一样。在请求中检查文件时,req.file 未定义。
function multerStore() {
return multer.diskStorage({
destination: function (req, file, cb) {
console.log(req);
execHomeDir().then(resp => {
const nameo = resp.replace("\n", "");
const folderPath = nameo + attachmentTemp;
createFolder(folderPath).then(resp=>{
cb(null, folderPath);
}).catch(ree=>{
cb(null, folderPath);
});
}).catch(ree => {
console.error('Error Multer');
console.error(ree);
const nameo = ree.replace("\n", "");
const folderPath = nameo + attachmentTemp;
createFolder(folderPath).then(resp=>{
cb(null, folderPath);
}).catch(ree=>{
cb(null, folderPath);
});
});
},
filename: function (req, file, cb) {
console.log(req);
console.log('Incoming file'+file.filename);
const name = setFileName('mexuser') + file.originalname;
cb(null, name);
}
});}
function multerOps() {
return multer({ storage: multerStore(), limits: fileLimiter });}const attachOps = multerOps('attachment', attachmentTemp);fileRouter.post('/:type', attachOps.single('attachment'),files.upload);
解决方案
推荐阅读
- javascript - 如何从资产文件夹中导入多张图片
- python-3.x - 如何动态替换 tkinter 标签(更新的数据在 for 循环内)
- python - 如何在曲面图上投影一条线?
- python - 如何从 Python 中的两个列表生成 json
- javascript - 无法让我的网站在移动浏览器中全屏运行(保存到主屏幕时)
- c# - 如何使用 Dart sha256 和 C# sha256 获得相同的结果?
- sql - 如果它不存在,则在表中插入一行 - Oracle
- ssl - 如何在 golang 中创建没有证书的 TLS 连接?
- python - python 辅助函数和返回语句
- reactjs - React Native - 无法在不点击的情况下呈现来自后端 api 的响应