multer/express/node.js图片上传实例

2021-06-16 01:03

阅读:627

let multer = require(‘multer‘) let storage = multer.diskStorage({ destination : (req,file,cb)=>{ //保存在public文件夹的upload文件夹里 cb(null,path.join(__dirname, ‘../public/upload/‘)) }, filename:(req,file,cb)=>{ cb(null,file.originalname) } }) let upload = multer({ storage: storage }) router.post(‘/‘, upload.single(‘avatar‘), function (req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.send({ code: 1, message: ‘successs‘ }) })

上一篇:Jquery滚动监听和附加导航

下一篇:PHP


评论


亲,登录后才可以留言!