"path" 参数必须是字符串类型。收到未定义 - 使用 multer 上传文件
The "path" argument must be of type string. Received undefined - File upload with multer
我正在尝试使用 multer 上传文件,但收到此错误消息。
internal/validators.js:117
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
^
TypeError [ERR_INVALID_ARG_TYPE] [ERR_INVALID_ARG_TYPE]: The "path"
argument must be of type string. Received undefined
当我从 angular 和 postman 尝试时,我遇到了这个问题。
我的代码:
import multer from 'multer';
export const upload = multer({
storage: multer.diskStorage({
destination: (req, file, cb) => cb(null, process.env.HOST_PORTAL_DIR),
filename: (req, file, cb) => cb(null, helpers.generateFileId(file.mimetype)),
}),
}).single('file');
router.post('/', function (req, res) {
upload(req, res, function (err) {
if (err instanceof multer.MulterError) {
console.log('Multer error', err);
} else if (err) {
console.log('unknown error', err);
}
});
});
我认为是因为环境变量将其更改为本地文件存储,然后重试。
我正在尝试使用 multer 上传文件,但收到此错误消息。
internal/validators.js:117
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
^
TypeError [ERR_INVALID_ARG_TYPE] [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
当我从 angular 和 postman 尝试时,我遇到了这个问题。 我的代码:
import multer from 'multer';
export const upload = multer({
storage: multer.diskStorage({
destination: (req, file, cb) => cb(null, process.env.HOST_PORTAL_DIR),
filename: (req, file, cb) => cb(null, helpers.generateFileId(file.mimetype)),
}),
}).single('file');
router.post('/', function (req, res) {
upload(req, res, function (err) {
if (err instanceof multer.MulterError) {
console.log('Multer error', err);
} else if (err) {
console.log('unknown error', err);
}
});
});
我认为是因为环境变量将其更改为本地文件存储,然后重试。