Search code examples
springpostmanspring-restcontrolleradvanced-rest-client

Multipart file (not given condition).Error-400(bad request)


My rest api is.

@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)

I need to check the condition like without browsing the file.

my input format is

Headers :

tenantId : ***

Body : selecting "formdata" (Postman), "multipart-formdata" (AdvancedRestClient)

card : without browsing file

Then i am getting the following error in Postman.

 {
"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"
  }

If i try in the AdvancedRest client with same input

I am getting the different error.

  {
"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" 
  
  } 

Is there any reason for different outputs and can i check the api without browsing file.


Solution

  • @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){
    
    }
    

    User @RequestPart instead of @RequestParam