Reputation: 12391
Posting data to an endpoint which is working fine when I select raw
and send json.
I am not receiving anything when I select form-data
. I have already defined them in my server.js
.
server.js config:
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const app = express();
var corsOptions = {
origin: "http://localhost:8081"
};
app.use(cors(corsOptions));
app.use(express.static('app/uploaded'));
// parse requests of content-type - application/json
app.use(bodyParser.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
Here is the postman request.
Upvotes: 0
Views: 2423
Reputation: 851
hi for parsing different form of data you have to add different middleware to access it
here is the code for parsing response:
var express = require('express');
var bodyParser = require('body-parser');
var multer = require('multer');
var upload = multer();
var app = express();
// for parsing application/json
app.use(bodyParser.json());
// for parsing application/xwww-
app.use(bodyParser.urlencoded({ extended: true }));
//form-urlencoded
// for parsing multipart/form-data
app.use(upload.array());
refer this doc for more detail documentation of body-parser with form data
let me know if its help
Upvotes: 3