Attachment file via REST API call

Hello everyone,

We are analyzing Flowable as a central process server to any application that need a workflow in our organization.

I have a spring boot app that read a form and sends it. If the field is a file type a POST to /flowable-task/content-api/content-service/content-items/ with this JSON request (example) is sent

  {
	"name" : "test_doc.pdf",
	"file" : "JVBERi0xLjYNJeLjz9MNCjE4IDAgb2JqDTw8L0xpbmVhcml6ZWQg..."
  }

And a 201 and and id is returned. “file” is the binary array content of the file.
But if I request a GET to /flowable-task/content-api/content-service/content-items/[id]/data I receive

{
   "message": "Internal server error",
   "exception": "No data available for content item [id]"
}

If I request a GET to /flowable-task/content-api/content-service/content-items/[id] I receive

{
   "id": [id],
   "name": "test_doc.pdf",
   "mimeType": "application/pdf",
   "taskId": null,
   "processInstanceId": null,
   "contentStoreId": null,
   "contentStoreName": null,
   "contentAvailable": false,
   "tenantId": "",
   "created": "2019-05-23T15:19:12.357+02:00",
   "createdBy": "jack",
   "lastModified": "2019-05-23T15:19:12.357+02:00",
   "lastModifiedBy": "jack",
   "url": "http://xxx:8080/flowable-task/content-api/content-service/content-items/[id]"
}

One thing that bothers me is the property “contentAvailable”: false but I can’t change it to true. The file uploaded directly to the form in /flowable-tasks/ have the property “contentAvailable” : true and can be downloaded correctly.

The only “documentation” that I found is: https://github.com/flowable/flowable-engine/blob/master/docs/public-api/references/openapi/content/flowable-oas-content.yaml

Anyone knows how this request to /flowable-task/content-api/content-service/content-items is done? What’s the JSON format of the request?

Thank you in advance

Ok, solved it!

The value of “file” in the JSON request has to be a FileSystemResource (not a binary array as documented).
An example done with springboot could be:

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
				
MultiValueMap<String, Object> body = new LinkedMultiValueMap<String, Object>();
body.add("name", part.getSubmittedFileName());
body.add("file", new FileSystemResource(tmpFile));
body.add("mimeType", part.getContentType());
				
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
				
ResponseEntity<String> answer =	restTemplate.postForEntity(URL_UPLOAD_FILE, requestEntity, String.class);

Regards