Javascript React/Express:POST错误413:负载太大(Bodyparser不工作)

Javascript React/Express:POST错误413:负载太大(Bodyparser不工作),javascript,node.js,reactjs,express,body-parser,Javascript,Node.js,Reactjs,Express,Body Parser,我什么都试过了,但这似乎不可能解决。我浏览了stackoverflow,浏览了3个谷歌页面 我尝试过的事情 在bodyParser.json中添加了extended:true/false 已使用bodyParser.urlencoder() 切换并使用multer extension following,但不断出现路径未找到错误 谁来帮忙 React手动打印功能: async function handlePrinting (file) { const raw = file.getFil

我什么都试过了,但这似乎不可能解决。我浏览了stackoverflow,浏览了3个谷歌页面

我尝试过的事情

  • 在bodyParser.json中添加了
    extended:true/false
  • 已使用bodyParser.urlencoder()
  • 切换并使用multer extension following,但不断出现
    路径未找到
    错误
  • 谁来帮忙

    React手动打印功能:

    async function handlePrinting (file) {
        const raw = file.getFileEncodeBase64String()
        const destination = 'printer'
        const key = file.file.lastModified
        var data = {
          raw: raw,
          pageRanges: pageRanges,
          sides: sides,
          copies: copies,
          destination: destination,
          key: key
        }
    
        await axios
          .post('/api/print/submit', data)
          .then(res => {
            console.log(res)
          })
          .catch(err => {
            console.log(err)
        })
      }
    
    快递:

    router.use(bodyParser.json({
      parameterLimit: 100000,
      limit: '50mb'
    }))
    
    router.post('/submit', (req, res) => {
      const data = {
        raw: req.body.raw,
        pageRanges: req.body.pageRanges,
        sides: req.body.sides,
        copies: req.body.copies,
        destination: req.body.destination,
        key: req.body.key,
      }
    
      Print.create(data, (error, post) => {
        if (error) {
          console.log(`Printing submit error: ${error}`)
          return res.sendStatus(BAD_REQUEST)
        }
    
        printFunction(data.raw, data.copies, data.sides, data.pageRanges, data.destination)
        return res.status(OK).send(post)
      })
    })
    

    我不确定这是否有帮助,您是否尝试过使用压缩

    易于使用

    进口

    const compression = require('compression');
    
    使用

    另一种方法是不使用主体解析器,我通常不使用

    app.use(express.json());
    
    然后发送

    return res.status(200).json({data:data});
    

    我想知道是否因为您在路由器级别设置解析器,应用程序限制正在覆盖路由器。您可以尝试在应用程序级别应用相同的设置吗?您使用哪个node.js版本?尝试使用最新的node.js版本。我使用node 13.5.0更改应用程序的限制不起作用。在深入研究了节点模块之后,我发现如果我手动将options.limit的值从100kb更改为50mb,它就会起作用。所以问题是我实际上没有在router.use中调用bodyParser.json函数。
    return res.status(200).json({data:data});