【问题标题】:Why can't send form-data in postman为什么不能在邮递员中发送表单数据
【发布时间】:2022-08-24 22:13:41
【问题描述】:

尝试在邮递员中发送表单数据并续集返回错误: value cannot be null

但是当使用 json 发送原始请求时一切正常。尝试 body-parser 和 multart,但没有任何效果

这是我的 index.ts

import express from \"express\";
...


const app = express()
const PORT = process.env.PORT || 5100

app.use(cors())
app.use(express.json())
app.use(\'/api\', router)
app.use(fileUpload({}))
app.use(errorHandler)

const start = async () => {
    try {
        await sequelize.authenticate()
        await sequelize.sync()
        console.log(chalk.cyanBright(\'Successful conection to data base\'));
        app.listen(PORT, () => { console.log(chalk.cyanBright(`Server has been started on port ${PORT}`)) })

    }
    catch (e) {
        console.log(e);
    }
}

start()

    标签: json typescript express postman middleware


    【解决方案1】:
    app.use(express.json())
    

    您有 JSON 请求正文的正文解析中间件。

    您没有用于多部分/表单数据请求正文的正文解析中间件。 documentation for body-parser 列出了您可以使用的几个中间件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-23
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 2021-11-19
      • 2018-11-15
      • 2021-09-01
      • 1970-01-01
      相关资源
      最近更新 更多