2020-02-16 21:52:38 +08:00
|
|
|
const express = require('express')
|
|
|
|
const multer = require('multer')
|
|
|
|
const cors = require('cors')
|
|
|
|
const path = require('path')
|
2020-02-17 15:36:36 +08:00
|
|
|
const fs = require('fs')
|
2020-02-16 21:52:38 +08:00
|
|
|
|
|
|
|
const app = express()
|
2020-02-17 15:36:36 +08:00
|
|
|
const dest = path.resolve(__dirname, 'temp')
|
|
|
|
const upload = multer({ dest })
|
2020-02-16 21:52:38 +08:00
|
|
|
|
|
|
|
app.options('/upload-test', cors())
|
2020-02-17 15:36:36 +08:00
|
|
|
app.post(
|
|
|
|
'/upload-test',
|
|
|
|
cors(),
|
|
|
|
function (req, res, next) {
|
|
|
|
req.on('close', () => {
|
|
|
|
console.log('文件上传取消')
|
|
|
|
})
|
|
|
|
req.on('error', () => {
|
|
|
|
console.log('文件上传出错')
|
|
|
|
})
|
|
|
|
next()
|
|
|
|
},
|
|
|
|
upload.any(),
|
|
|
|
function (req, res, next) {
|
|
|
|
if (!fs.existsSync(dest)) fs.mkdirSync(dest)
|
2020-02-18 15:15:42 +08:00
|
|
|
console.log(req.headers)
|
|
|
|
console.log(req.body)
|
2020-02-17 15:36:36 +08:00
|
|
|
res.send('very good')
|
|
|
|
}
|
|
|
|
)
|
2020-02-16 21:52:38 +08:00
|
|
|
|
|
|
|
app.listen(3000)
|