node.js 获取el-upload后台数据。

安装好,koa-body.

const Koa = require('koa');
const app = new Koa();
const cors=require('koa2-cors')
const InitManager = require('./core/init')
//const parser= require('koa-bodyparser')
const koaBody=require('koa-body')
const catchError = require('./middlewares/catchError')


app.use(catchError)
app.use(cors({
    origin:['http://localhost:9528'],
    credentials:true
}))
//app.use(parser({multipart: true,}))
app.use(koaBody({
    multipart: true,
}))
InitManager.initCore(app)
require('./app/model/user')


app.listen(3000);

////

app.use(koaBody({

    multipart: true,

}))

//https://localhost:3000/v1/spu/id/img,
router.post('/id/img', async (ctx, next)=>{

     
    
     console.log(ctx.request.files)
})


{
  file: File {
    _events: [Object: null prototype] {},
    _eventsCount: 0,
    _maxListeners: undefined,
    size: 879394,
    path: 'C:\\Users\\lenovo\\AppData\\Local\\Temp\\upload_6d0134c522b89ee0449f11789d8dbc27',
    name: 'Chrysanthemum.jpg',
    type: 'image/jpeg',
    hash: null,
    lastModifiedDate: 2020-07-12T05:30:41.398Z,
    _writeStream: WriteStream {
      _writableState: [WritableState],
      writable: false,
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      path: 'C:\\Users\\lenovo\\AppData\\Local\\Temp\\upload_6d0134c522b89ee0449f11789d8dbc27',
      fd: null,
      flags: 'w',
      mode: 438,
      start: undefined,
      autoClose: true,
      pos: undefined,
      bytesWritten: 879394,
      closed: false,
      [Symbol(kCapture)]: false,
      [Symbol(kIsPerformingIO)]: false
    },
    [Symbol(kCapture)]: false
  }
}

在ctx.request.files中获取信息

你可能感兴趣的:(javascript)