当我上传带有multer中间件的图像时,我得到了未定义的文件图像。换句话说,我无法从我上传的文件中获取名称或文件扩展名。我不知道这是milter的错误。 这是我的js文件:
var express = require('express');
var multer = require('multer');
var upload = multer({dest:'uploads/'});
var router = express.Router();
router.post('/register', upload.single('profile'), function(req, res, next){
if(req.file){
console.log("Uploading files");
//get all Properties of the files object
var profileImageOriginalName = req.file.profile.originalname;
var profileImageName = req.file.profile.name;
var profileImageMime = req.file.profile.mimetype;
var profileImagePath = req.file.profile.path;
var profileImageExt = req.file.profile.extension;
var profileImageSize = req.file.profile.size;
}

这是我的玉格式:
的html表单文件
input.form-control(name = 'profile', type = 'file')

类型错误:无法读取未定义的原始名称
答案 0 :(得分:0)
对于.single()
,req.file
直接包含文件属性(例如req.file.originalname
)。