question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON array directly in request body is interpreted as Object

See original GitHub issue

Support plan

  • Which support plan is this issue covered by? (Community, Sponsor, Enterprise): Community
  • Currently blocking your project/work? (yes/no): yes
  • Affecting a production system? (yes/no): no

Context

  • Node.js version: 16, but probably all
  • Release Line of Formidable (Legacy, Current, Next): v2
  • Formidable exact version: 2.0.1
  • Environment (node, browser, native, OS): node
  • Used with (popular names of modules): express

What are you trying to achieve or the steps to reproduce?

function formidableMiddleWare(options = {}) {
	return (req, _res, next) => {
		const form = formidable(options);

		form.parse(req, (err, fields, files) => {
			if (err) {
				logger.error('Parsing of form', options, err);

				next(err);
				return;
			}

			req.body = fields
			next();
		});
	};
};
app.post(
  '/form',
  formidableMiddleWare({
    // Do not accept any file by default!
    filter: () => false,
  }),
  (req, res) => {
    res.json({
      req,
      isArray: Array.isArray(req),
    });
  },
);

What was the result you got?

The result of form.parse is an Object not Array

What result did you expect?

The result of form.parse should be an Array.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
Akxecommented, Apr 28, 2022

How is this a solution to this problem?

4reactions
GrosSacASaccommented, Apr 28, 2022

Don’t use webpack

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - How to directly read this JsonArray which comes in a ...
How to directly read this JsonArray which comes in a RequestBody ; @PostMapping("/certificates") public ResponseEntity<String> postCertificates ...
Read more >
Convert JSON Response Body to Java Object - Tools QA
This tutorial explains How to convert or parse JSON Response Body to Java Object (POJO) using Deserializing in Java with examples.
Read more >
How JSON Array of String Works? (Examples) - eduCBA
We have seen how JSON array represents an ordered list of values be it string, numbers, Boolean, or an object. Here as per...
Read more >
JSON Stringify Example – How to Parse a JSON Object with JS
JSON arrays work pretty much the same way as arrays in JavaScript, and can contain strings, booleans, numbers, and other JSON objects.
Read more >
How to create JSON Array Request Body
In the last tutorial, I explained How to test POST JSON Object request using Java Map in Rest Assured. In this tutorial, I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found