node+ajax实现多张图片上传

前台代码



	
		
		
	
	
		

后台代码
  var multer = require("multer");
var storage = multer.diskStorage({
  	destination: function (req, file, cb) {
	    cb(null, './public/upload')
  	},
  	filename: function (req, file, cb) {
	  	var str = file.originalname.split('.');
	    cb(null, Date.now()+'.'+str[1]);
  	}
})
var upload = multer({ storage: storage });
app.post("/uploadImgs",upload.array("file",20),function(req,res,next){
	
	var arr = [];
	for(var i in req.files){
		
		arr.push(req.files[i].path);
	}
	res.json({
		code:200,
		data:arr
	})
})

你可能感兴趣的:(Node.js,JavaScript武器库,Node.js开发指南,微信小程序)