How does koa-body get the information uploaded to the front-end page file?

Let"s briefly describe the project first

  • spa application of version 6.x of view layer angualr.js
  • angular calls the api API of node directly, and node invokes the service to add, delete, modify and query
  • node version 8.11.x mainly uses koa2 framework and koa-body (^ 4.0.4), koa-router (^ 7.1.1) as request resolution

requirements are as follows

  • now there is a file upload requirement, but node is only used for forwarding and does not actually save the file, but calls the service api to operate
// angular 
let formData:FormData = new FormData();
    formData.append("file",this.fileData);  // this.fileinput file 
    formData.append("name","");
    this.http.upload("assets/upload/add",formData, (data) => {
      console.log(data)
    }, (error) => {

    });
// node
const koaBody = require("koa-body");    
app.use(koaBody(
    multipart: true,
    formidable: {
      maxFileSize: 200 * 1024 * 1024 // 2M
    }
));

router.post("/upload/add", async (ctx, next) => {
  console.log(ctx.request.files);  // undefined
  console.log(ctx.request.body);   // {}
  ctx.body = JSON.stringify(ctx.request.files); // 
});

foreground page setup request header "Content-Type":" multipart/form-data;" sends data normally, and everything is normal.
now I want to upload the file to the server by calling the server api if I don"t store any files on the node side, but ctx.request.files doesn"t have any data. If there are other ways, you can also share

.

if it is version 4 of koabody
const file = ctx.request.files.file; / / get uploaded file

if it is version 3 of koabody
const file = ctx.request.file; / / get uploaded file

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3fbd1-64e74.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3fbd1-64e74.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?