Can we send MultipartFile inside a Custom Request Object in a Rest Template call? Similarly, can we receive a MutlipartFile inside a Custom Response Object returned from a Rest call made through the Rest Template?
Basically, we need to send other essential attributes along with a File Upload and receive few attributes along with a File Download.
Is this possible through a Spring Rest Template?
Below is the Code,
public class UploadRequest {
private Long checkSum;
private MultiPartFile fileContents;
//setters and getters
}
We receive the MultipartFile from a controller end point, we just relay it to another endpoint using the below is the Rest template call,
HttpHeaders headers = new HttpHeaders();
headers.setContentType("mutipart/form-data");
MultiValueMap<String, Object> map = new MultiValueMap<>();
map.add("uploadRequest", uploadRequest);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);
ResponseEntity<UploadResponse> responseEntity = restTemplate.postForEntity(uploadUrl, requestEntity, UploadResponse.class);
it results in the below exception,
com.fasterxml.jackson.databind.exc.InvalidDefinitionException No Serializer for class java.io.FileDescriptor
and
no properties discovered to create BeanSerializer