The problem of uploading node koa2 images to debugger

first of all, we need to build a koa2 environment, so I won"t say much about it here.

next you need to load koa-multer:

npm install koa-multer-- save

the specific code is as follows:

first is the js section:

const multer = require("koa-multer");//koa-multer
//
//
var storage = multer.diskStorage({
  //
  destination: function (req, file, cb) {
    cb(null, "public/uploads/")
  },
  //
  filename: function (req, file, cb) {
    var fileFormat = (file.originalname).split(".");
    cb(null,Date.now() + "." + fileFormat[fileFormat.length - 1]);
  }
})
//
var upload = multer({ storage: storage });
//
router.post("/upload", upload.single("file"), async (ctx, next) => {
   conso.log("debugger"); 
  ctx.body = {
    filename: ctx.req.file.filename//
  }
})

there is no problem with saving pictures. The code behind the post request cannot use debugger, to ask for advice, or other image upload methods can also be used

Apr.16,2021
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-1b3b401-2c286.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-1b3b401-2c286.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?