I use RestTemaplteBuilder for send POST request to Telegram Bot API. There was a problem creating the request to upload the audio file. According to the documentation - https://core.telegram.org/bots/api#sending-files you need to send a request of type multipart/form-data. Error: 413 Request Entity Too Large
MultiValueMap<String, Object> request= new LinkedMultiValueMap<String, Object>();
try {
parts.set("chat_id", "id");
parts.set("audio", (Files.readAllBytes(Paths.get(ClassLoader.getSystemResource("name.mp3").toURI()))));
} catch (Exception e) {
e.printStackTrace();
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String, Object>>(request, headers);
ResponseEntity<String> responseEntity = restTemplateBuilder.build().postForEntity(requestFormatter(URL_BOT_PREFIX, method), requestEntity, String.class);