How to convert file uploaded in Form into File object?

Hi Team,

As we all are aware that we can not use Http Task to invoke REST API which accepts Multipart File as a form-data input. So I am trying to achieve this inside Script using RestTemplate.

Script is as per below :

import org.flowable.content.engine.ContentEngines;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

out.println(execution.getVariable("iddocument"));

InputStream is = ContentEngines.getDefaultContentEngine().getContentService().getContentItemData(((java.util.ArrayList)execution.getVariable("iddocument")).get(0).getId());

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.setBearerAuth("058c6c92-xxxx-xxxx-xxxx-7cc795d773ed");
MultiValueMap<String, Object> body = new LinkedMultiValueMap<String, Object>();

// I need a way to get the file uploaded inside a Form with variable name "iddocument" into File object so that I can provide file to FileSystemResource.
// Can we convert InputStream is to FileSystemResource?

body.add("multipartFile", new FileSystemResource(file));
body.add("docType", "aadhaar");

String uploadUrl = "REST_API_ENDPOINT";

RestTemplate restTemplate = new RestTemplate();
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
ResponseEntity<String> response = restTemplate.postForEntity(uploadUrl, requestEntity, String.class);
System.out.println("Response Code: "+response.getStatusCode());

Is there any other way to invoke REST API which accepts Multipart File?