鲻鱼 'filesLeft[file.fieldname]' 未定义
multer 'filesLeft[file.fieldname]' undefined
我是 multer 的新手,我正在尝试上传文件以使用 multer 表达服务器,客户端是 ReactJS:
快递 - 4.15.2
多-1.3.0
公理 - 0.16.1
反应 - 15.5.4
客户端(ReactJS):
<form onSubmit={this.onFilesUpload} enctype="multipart/form-data">
<input type='file' ref={(input) => this.filesInput = input} name='inputFile'/>
<button type='submit' >upload</button>
</form>
我正在以表格数据发送文件:
var data = new FormData();
const files = this.filesInput.files;
for(var key in files) {
if (files.hasOwnProperty(key) && files[key] instanceof File) {
data.append(key, files[key]);
}
}
在服务器端:
const express = require('express'),
bodyParser = require('body-parser'),
cors = require('cors'),
router = require('./routes/router'),
mongoose = require('mongoose'),
multer = require('multer'),
app = express();
....
app.use(bodyParser.urlencoded({ extended: false }));
app.use(multer({dest: './public/uploads/}).single('inputFile));
app.use(bodyParser.json());
app.use(cors());
router(app);
我从 multer 模块代码中得到 LIMIT_UNEXPECTED_FILE 异常 -
node_module\multer\index.js.
为了解决这个问题,更改了客户端代码:
var data = new FormData();
const inputFile = this.filesInput.files[0];
data.append('file', inputFile);
我是 multer 的新手,我正在尝试上传文件以使用 multer 表达服务器,客户端是 ReactJS:
快递 - 4.15.2 多-1.3.0 公理 - 0.16.1 反应 - 15.5.4
客户端(ReactJS):
<form onSubmit={this.onFilesUpload} enctype="multipart/form-data">
<input type='file' ref={(input) => this.filesInput = input} name='inputFile'/>
<button type='submit' >upload</button>
</form>
我正在以表格数据发送文件:
var data = new FormData();
const files = this.filesInput.files;
for(var key in files) {
if (files.hasOwnProperty(key) && files[key] instanceof File) {
data.append(key, files[key]);
}
}
在服务器端:
const express = require('express'),
bodyParser = require('body-parser'),
cors = require('cors'),
router = require('./routes/router'),
mongoose = require('mongoose'),
multer = require('multer'),
app = express();
....
app.use(bodyParser.urlencoded({ extended: false }));
app.use(multer({dest: './public/uploads/}).single('inputFile));
app.use(bodyParser.json());
app.use(cors());
router(app);
我从 multer 模块代码中得到 LIMIT_UNEXPECTED_FILE 异常 - node_module\multer\index.js.
为了解决这个问题,更改了客户端代码:
var data = new FormData();
const inputFile = this.filesInput.files[0];
data.append('file', inputFile);