马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
let express = require('express');
let http = require('http');
let fs = require('fs');
let path = require("path");
let multer = require("multer");
let app = express();
let upload = multer({
dest: "upload" //上传文件存放路径
});
app.use(express.static(path.join(__dirname, 'upload')));
let singleMidle = upload.single("singleFile"); //一次处理一张
let singleMidle2 = upload.single("sigfile"); //一次处理一张
let arrMidle = upload.array("arrayFile", 5); //一次最多处理5张
let arrMidle2 = upload.array("mulfile", 5); //一次最多处理5张
app.post("/multer/singup", singleMidle, function(req, res) {
res.send(req.file);
});
app.post('/multer/arrup', arrMidle, function(req, res) {
console.log(req.files);
res.send(req.files);
});
app.post('/ajaxupload', arrMidle2, function(req, res) {
console.log(req.files);
res.send(req.files);
});
app.post('/ajaxsigupload', singleMidle2, function(req, res) {
console.log(req.file);
res.send(req.file);
});
app.get('/', function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
url2 = "./testip.html";
fs.readFile(url2, 'utf-8', function(err, data) {
if (err) {
throw err;
}
res.end(data);
});
})
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Headers', '*');
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS,PATCH");
next();
});
app.listen(3000);
console.log("请使用http://localhost:3000/访问主页,或者http://127.0.0.1:3000/访问主页");
|