I know how to upload multipart file from postman, but how to do the same through REST API. The consumer API works fine when I hit through postman, but while doing the same through REST, it does not work.

[![enter image description here](https://i.stack.imgur.com/IDM0O.png)](https://i.stack.imgur.com/IDM0O.png)

Same thing I am doing through REST like this but its not working:

```java
    HttpHeaders headers = new HttpHeaders();
                    headers.setContentType(MediaType.MULTIPART_FORM_DATA);

                    MultiValueMap<String, Object> body
                            = new LinkedMultiValueMap<>();
                    body.add("file", file);

                    HttpEntity<MultiValueMap<String, Object>> requestEntity
                            = new HttpEntity<>(body, headers);

                    String serverUrl = "http://localhost:9001/communication/api/messageEngine/event/RECIPT/sendEmailAttachment";

                    ParameterizedTypeReference<ApiResponse<Map<String,Object>>> parameterizedTypeReference =
                            new ParameterizedTypeReference<com.loylty.dataacquisition.model.ApiResponse<Map<String,Object>>>() {};

                    RestTemplate restTemplate = new RestTemplate();
                    try {
                        ResponseEntity<com.loylty.dataacquisition.model.ApiResponse<Map<String,Object>>> result =
                                restTemplate.exchange(serverUrl, HttpMethod.POST, requestEntity, parameterizedTypeReference);
                        if (result.getStatusCode().is2xxSuccessful() == false) {
                            throw new DENotReachableException();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        throw e;
                    }

```

**Target API or consumer API**:

```
     @CrossOrigin
    @RequestMapping(method = RequestMethod.POST, value = "/event/{event}/sendEmailAttachment", consumes = {"multipart/form-data"})
    public ApiResponse<Object> sendReceiptWithAttachment(@RequestPart("file") MultipartFile file, @PathVariable("event") String event) {

        LidsysUtil.messageId.set(String.valueOf(new Date().getTime()));

        MessageTracker tracker = new MessageTracker(LidsysUtil.messageId.get(), event);
        LidsysUtil.tracker.set(tracker);
        LOGGER.info("Executing Message Id : {} ", LidsysUtil.messageId.get());
        LOGGER.info("Request received for event : {}", event);
       // LOGGER.info("Request Body : {}", LidsysUtil.displayJSON(requestBody));
        Map<String, Object> request = messageEngineService.initiateEmailwithAttachmentV2( file, event);

        return new ApiResponse<>(APIResponseKey.ALL_GOOD, messageEngineService.execute(request, event), null);
    }

```

Following exception I get when I try with REST api

**Exception on source microservice**

```
020-10-21 19:11:18,237 [ERROR]---[DirectJDKLog.java]---[http-nio-8010-exec-2]: Servlet.service() for servlet [dispatcherServlet] in context with path [/dataacquisition] threw exception [Request processing failed; nested exception is org.springframework.web.client.HttpClientErrorException: 400 null] with root cause
org.springframework.web.client.HttpClientErrorException: 400 null

```

**Exception on target microservice**

```
2020-10-21 19:11:17,445 [ERROR]---[HttpLoggingFilter.java]---[http-nio-9001-exec-10]: null

```