文件上传管理

文件上传管理

Voun MAX++

Multer 是一个 node.js 中间件,用于处理 multipart/form-data 类型的表单数据,它主要用于上传文件。

注意: Multer 不会处理任何非 multipart/form-data 类型的表单数据。

1
npm install --save multer
1
2
3
4
5
6
7
8
9
10
11
12
13
//前后端分离-前端

const params = new FormData()
params.append('kerwinfile', file.file)
params.append('username', this.username)
const config = {
headers: {
"Content-Type":"multipart/form-data"
}
}
http.post('/api/upload', params, config).then(res => {
this.imgpath = 'http://localhost:3000' + res.data
})

Multer 会添加一个 body 对象 以及 filefiles 对象 到 express 的 request 对象中。 body 对象包含表单的文本域信息,filefiles 对象包含对象表单上传的文件信息。

1
2
3
4
//前后端分离-后端
router.post('/upload', upload.single('kerwinfile'),function(req, res, next) {
console.log(req.file)
})
  • 标题: 文件上传管理
  • 作者: Voun
  • 创建于 : 2023-08-04 16:14:00
  • 更新于 : 2024-08-13 05:34:32
  • 链接: http://www.voun.top/2023/08/04/06FileUpload/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
此页目录
文件上传管理