当我从postman> body> row发送请求并且content-type是application / JSON时,我的请求成功了,但是与我尝试从multipart / form-data发送的方式相同,它抛出400错误。
我也更改了邮递员的标头部分的标头部分,即使它给出了相同的错误。
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);
});
};
我得到的输出低于200作为成功响应
{ “ _id”:“ 5d3d5e33b0e15a1adc718a1e”, “ setId”:“ 5d384fdbc999c40b08ec4ed2” }
然后当我应用表单数据时
{
"error": {
"setId": {
"message": "Field is required",
"name": "ValidatorError",
"properties": {
"message": "Field is required",
"type": "required",
"path": "setId"
},
"kind": "required",
"path": "setId"
}
},
"message": "Invalid Payload"
}