Skip to content

How to pass file object in request form data using resttemplate #1

Description

@bossReact

while sending the request using resttemplate, I set the content type as multipart/form-data but it had not worked.
code :
MultiValueMap<String, Object> bodyMap = new LinkedMultiValueMap<>();
String token="01OZX5nhEuRR0aje3iG1wPs6PkpFdUTGPiastIoVzpLdoHdFNBDz-DWZkm9pdmqJq1XOQOziMeYYVFdfBGv43XgNzIGzA";
File file= new File("E:/mp3/AAJA MAHIYA.MP3");
bodyMap.add("media", file);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.setBearerAuth(token);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(bodyMap, headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity response = restTemplate.exchange("https://api.temi.com/v1/jobs",
HttpMethod.POST, requestEntity, String.class);
System.out.println("response status: " + response.getStatusCode());
System.out.println("response body: " + response.getBody());

But this code throws bad request 400.
but same thing i do with postman response code is 403 (account still not subscribed).

I need to send file object from body and then form data it can be possible by using resttemplate?
please refer the attachment.

I need help.
Thanks in advance.
form-data

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions