"Nein geeigneter httpMessageConverter gefunden".
Code: Select all
try {
// Setting headers for the file part
HttpHeaders fileHeaders = new HttpHeaders();
fileHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
fileHeaders.setBearerAuth("auth_token");
MultiValueMap map = new LinkedMultiValueMap();
map.add("file", new File(path));
HttpEntity fileEntity = new HttpEntity(map, fileHeaders);
// Setting headers for the JSON part
HttpHeaders jsonHeaders = new HttpHeaders();
jsonHeaders.setContentType(MediaType.APPLICATION_JSON);
jsonHeaders.setBearerAuth("auth_token");
String jsonString = new ObjectMapper().writeValueAsString(jsonObject);
HttpEntity jsonEntity = new HttpEntity(jsonString, jsonHeaders);
// Creating the multipart request
MultiValueMap requestBody = new LinkedMultiValueMap();
requestBody.add("file", fileEntity);
requestBody.add("metadatak", jsonEntity);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.setBearerAuth("auth_token");
HttpEntity requestEntity = new HttpEntity(requestBody, headers);
ResponseEntity responseResult = template.postForEntity(url, requestEntity, String.class);
return ResponseEntity.ok(responseResult);
} catch (RestClientException rex) {
logger.error("RestClientException occurred: {}", rex.getMessage());
rex.printStackTrace();
return ResponseEntity.badRequest().build();
} catch (Exception ex) {
logger.error("Exception occured : " + ex);
ex.printStackTrace();
return ResponseEntity.status(400).build();
}
< /code>
Aber jedes Mal, wenn ich eine Ausnahme erhalte < /code> wie folgt: < /p>
org.springframework [org.springframework.util.linkedMultivalUeMap] < /p>
< /blockquote>
Ich kann nicht vorwärts gehen, da dieser Fehler mich wirklich behindert, um die Reaktion 200 (OK) zu erhalten. Kann jemand bitte vorschlagen, wo ich mich irre, um eine 200 (OK) Antwort aus dem Postmapping