0

I've tried everything but this just seems impossible to fix. I have browsed every proposed solution on stackoverflow and burned through 3 google pages.

Things I've tried

  1. Added extended: true/false within bodyParser.json
  2. Used bodyParser.urlencoder()
  3. Switched over and used multer extension following this tutorial but kept getting a path not found error.

Someone please help

React handlePrinting function:

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)
    })
  }

Express:

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)
  })
})
Jerry Lee
  • 1
  • 2
  • I wonder if because you are setting the parser at Router level, the application limit is overriding the Router. Could you try applying the same setting at app level? – James Jan 11 '20 at 02:36
  • which node.js version do you use? try with latest node.js version. – Shivaji Mutkule Jan 11 '20 at 12:02
  • I use node 13.5.0 – Jerry Lee Jan 11 '20 at 21:53
  • Changing the limit on the application limit did not work. After some digging in the node-modules, I found out that if I manually change the value of options.limit from 100kb to 50mb, it worked. So the problem was that I wasn't actually calling the bodyParser.json function in my router.use. – Jerry Lee Jan 11 '20 at 22:00

1 Answers1

0

I am unsure if this will help, have you tried using compression?

https://www.npmjs.com/package/compression

easy to use

import

const compression = require('compression');

use

app.use(compression());

another approach is do not use body parser, I don't usually.

app.use(express.json());

then to send

return res.status(200).json({data:data});
tim
  • 473
  • 5
  • 9