我正在尝试使用Express4和multer进行图像ajax上传,但它不起作用
这是我的请求截图
这是服务器脚本
var multer = require('multer');
var upload = multer({ dest: 'uploads/' });
var router = express.Router();
router.route('/upload')
.post(upload.single('file'), function(req, res) {
console.log(req.file);
//req.file is undefined
});
更新了客户端代码:
import Ember from 'ember';
export default Ember.TextField.extend({
type: 'file',
change: function(e) {
var inputFiles = e.target.files;
var inputFile = inputFiles[0];
var formData = new FormData();
formData.append('file', inputFile);
Ember.$.ajax({
type: 'POST',
url: '/upload',
data: formData,
cache: false,
contentType: false,
processData: false,
success: function(data) {
console.log(data);
},
error: function(err) {
console.error(err)
}
})
}
});