formdata params , array when length is 1, typeof it is string
See original GitHub issueContext
- node version: 6.11.1
- multer version: 1.3.0
- environment (node, browser): windows
What are you trying to achieve or the steps to reproduce ?
when I post a array length is 1 , the server accept it as String, but when the legnth > 1, typeof it is Object
Server
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var multer = require('multer')
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(multer({ dest: './uploads/'}).any())
app.post('/', function(req, res, next){
console.log("req.files.length", req.files.length)
console.log("req.body",req.body)
a = req.body.a; //the typeof a diffrent with it's length (but I want it as Object)
console.log("a", typeof(a), a);
return res.send(req.body || {})
});
// error handler
app.use(function(err, req, res, next) {
res.status(err.status || 500).send("error" + err);
});
var server = app.listen(3000, function() {
console.log("web server listening on port " + (server.address().port));
});
Test Demo
var assert = require("chai").assert
var request = require('request')
var url = "http://127.0.0.1:3000/"
describe("post", function(){
it('array length 1', function(done){
var opts = {
method: 'POST',
url: url,
formData: {
b: "hello",
a: [1]
}
};
request(opts, function(err, res, body){
assert.equal(null, err);
console.log("body", body);
done()
});
})
it('array length 2', function(done){
var opts = {
method: 'POST',
url: url,
formData: {
b: "hello",
a: [1 ,2 , 3]
}
};
request(opts, function(err, res, body){
assert.equal(null, err);
console.log("body", body);
done()
});
})
})
the first demo, typeof a is string, but the second a is Object,
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
appending array to FormData and send via AJAX
I'm using ajax to submit a multipart form with array, text fields and files. var attachments = document. getElementById('files'); var data= new FormData();...
Read more >Using FormData Objects - Web APIs | MDN
The FormData object lets you compile a set of key/value pairs to send using XMLHttpRequest. It is primarily intended for use in sending...
Read more >OpenAPI Specification - Version 2.0 - Swagger
The internal type of the array. The value MUST be one of "string" , "number" , "integer" , "boolean" , or "array" ....
Read more >$_FILES - Manual - PHP
Last I checked (a while ago now admittedly), if you use array parameters in ... @param string $fileDescriptionParam (name, type, tmp_name, error или...
Read more >Forms in HTML documents - W3C
Step one: Identify the successful controls; Step two: Build a form data set ... for text and passwd -- size CDATA #IMPLIED --...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am very grateful to you for your advice.
body-parser
doesn’t parsemultipart/form-data
, are you thinking of theapplication/x-www-form-urlencoded
format? They are quite different, I would advice you to google them to find out how they look 😃