【问题标题】:req.body gets empty when i am uploading files当我上传文件时,req.body 变空
【发布时间】:2016-02-29 15:13:11
【问题描述】:

我在 MEAN 堆栈中使用 Multer。 我想上传带有一些文本字段的文件。 使用 Postman 按字段和值从“表单数据”传递数据。 问题是当我同时传递文本字段和文件时,req.body 在“文件”字段之前获得所有值,但在文件字段之后没有获得任何值。

【问题讨论】:

  • 你试过enctype="multipart/form-data"吗?
  • { "status": "ERROR", "error_message": "Error: Multipart: Boundary not found" }

标签: node.js express multer


【解决方案1】:

在 express 中有一些使用 multer 的例子 https://github.com/expressjs/multer

 app.post('/profile', upload.single('avatar'), function (req, res, next) {
 // req.file is the `avatar` file
 // req.body will hold the text fields, if there were any
 })

【讨论】:

    猜你喜欢
    • 2020-08-08
    • 2023-03-05
    • 1970-01-01
    • 2017-05-01
    • 2016-12-18
    • 2019-02-10
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    相关资源
    最近更新 更多