我的REST API的。
@PutMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUEpath="/{referenceNumber}")
public void updateCard(@RequestHeader(value = tenantId) String theTenantId,
@PathVariable String referenceNumber,@RequestParam(value = "card")MultipartFile multipartFile,HttpServletRequest request)
我需要检查,如没有条件浏览文件。
我的输入格式为
头:
tenantId:***
正文:选择 “FORMDATA”(邮差), “多-FORMDATA”(AdvancedRestClient)
卡:无浏览文件
然后我得到的邮差下面的错误。
{
"timestamp": 1549351840816,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.web.multipart.support.MissingServletRequestPartException",
"message": "Required request part 'card' is not present",
"path": "/app-1.5.0/1.5/references/34a236d7-9305-402f-959d-8c83d5ededbb"
}
如果我尝试在高级REST客户端具有相同的输入
我收到了不同的错误。
{
"timestamp": 1549352119229,
"status": 415,
"error": "Unsupported Media Type",
"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Content type 'null' not supported",
"path": "/app-1.5.0/1.5/references/34a236d7-9305-402f-959d-8c83d5ededbb"
}
没有任何理由为不同的输出,我可以检查API无需浏览文件。
@PutMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUEpath="/{referenceNumber}")
public void updateCard(@RequestHeader(value = tenantId) String theTenantId,
@PathVariable String referenceNumber,@RequestPart(required = false,value = "card")MultipartFile multipartFile,HttpServletRequest request){
}
用户@RequestPart @RequestParam代替