0

When I am sending request from postman>body>row and content-type is application/JSON then my request is the successful but same way I am trying to send from multipart/form-data it throws 400 error.

I have changes the header part also in the header section of postman but even though it is giving the same error.

exports['v1'] = (request, response) => {
  /* Convert payload to Modal */
  console.log(request.body);
  const media = new MediaModel(request.body);

  /* Validate Payload */
  const error = media.validateSync();
  if (error) {
    return ResUtil.invalidInput(response, error.errors, 'Invalid Payload');
  }

  /* Process Request */
  MediaModel.collection.insertOne(media, (error, data) => {
    if (error) {
      return ResUtil.error(response, error, 'Error saving media');
    }
    return ResUtil.created(response, data);
  });
};

I am getting below as output as success 200 response

{ "_id": "5d3d5e33b0e15a1adc718a1e", "setId": "5d384fdbc999c40b08ec4ed2" }

and when I am applying form-data then

{
    "error": {
        "setId": {
            "message": "Field is required",
            "name": "ValidatorError",
            "properties": {
                "message": "Field is required",
                "type": "required",
                "path": "setId"
            },
            "kind": "required",
            "path": "setId"
        }
    },
    "message": "Invalid Payload"
}

0 Answers0