# How to convert file uploaded in Form into File object?

**URL:** <https://forum.flowable.org/t/how-to-convert-file-uploaded-in-form-into-file-object/9868>\
**Category:** Uncategorized\
**Created:** [November 2, 2022, 10:58am UTC](https://forum.flowable.org/t/how-to-convert-file-uploaded-in-form-into-file-object/9868 "2022-11-02T10:58:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuclearsagar](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/nuclearsagar/32/1451_2.png) [@nuclearsagar](https://forum.flowable.org/u/nuclearsagar)\
**Post date:** [November 2, 2022, 10:58am UTC](https://forum.flowable.org/t/how-to-convert-file-uploaded-in-form-into-file-object/9868/1 "2022-11-02T10:58:50Z")

</div>

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 :

```auto
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?
