I want to send a Multipart file through an API with contentType = multipart/form-data. When I am trying to send the request using restTemplate in Java SpringBoot. I am getting an exception
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class GlobalSendAttachmentRequest {
private String fileType;
private String sender;
private String messageStatus;
private String messageId;
private String chatId;
private long messageTimestamp;
private String userId;
private String sessionId;
private String messageType;
private MultipartFile multipartFile;
}
response = restClient.post(uriComponentsBuilder.build().toString(), getGlobalFileUploadHeaders(), request,
new ParameterizedTypeReference<GlobalSendAttachmentResponse>() {
});
@Retry(attempts = 3, types = {IOException.class, ResourceAccessException.class, HttpServerErrorException.class})
public <E, T> T post(String url, Map<String, String> headers,
E requestBody, ParameterizedTypeReference<T> respType) {
HttpEntity<E> httpEntity = new HttpEntity<>(requestBody, populateHeaders(headers));
long startTime = System.currentTimeMillis();
try {
ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, respType);
}
New contributor
Shivansh Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.