使用javascript的方式:
var data = new FormData();
$.each($("input[type='file']")[0].files, function(i, file) {
data.append('file', file);
});
$.ajax({
type: 'POST',
url: '/your/url',
cache: false,
contentType: false,
processData: false,
data : data,
success: function(result){
console.log(result);
},
error: function(err){
console.log(err);
}
})
如果多次调用data.append('file',file),您的请求将包含文件数组。
我自己使用node.js和多部分处理程序中间件multer来获取数据,如下所示:
router.post('/trip/save', upload.array('file', 10), function(req, res){
// Your array of files is in req.files
}