Upload file trought JAVA with bonita rest API



I'm trying to upload file in bonita to create a 'bonita temporaly file'.
The url is : http://:
To execute this call, we need to be connect and add bonita token and bonita cookie in the POST call.
So, i'm trying to do it like that ( with OKHttp ):

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
RequestBody body = RequestBody.create(mediaType, file);
Request.Builder requestBuilder = new Request.Builder()
    .addHeader("Content-Type", "multipart/form-data")
    .addHeader("Accept", "application/json")
    .addHeader("X-Bonita-API-Token", authenticationService.extractBonitaTokenFromCookie(authenticationResult))
    .addHeader("cache-control", "no-cache");

for (String aa :
    authenticationResult.getHeaders().get("Set-Cookie")) {
    requestBuilder.addHeader("Cookie", aa);

Request request = requestBuilder
Response response = client.newCall(request).execute();
ResponseBody result = response.body();

authenticationResult.getHeaders().get("Set-Cookie") contain a list with:
- JSESSIONID=6ECBA8154F52E34C796FBAB2569702C5; path=/bonita;
- bonita.tenant=1;
- X-Bonita-API-Token=321a90a4-dce9-4b5e-ab00-97f7ee2aded0;

When i'm doing that, i have an HTTP-200 but nothing in my body.
And when i'm doing this in Postman, i've got a response like:

I need to do this in order to instantiate a form.

Someone can help me ?


Submitted by GeekBot on Thu, 08/15/2019 - 11:42

I have the same problem. I saw another question on this issue, without clear answer on what to do. However, you can find demos on document manipulation and upload on the Bonita Github. https://github.com/Bonitasoft-Community/file-upload-download-example/rel...
After a few adaptation, you can see that demonstration works. But actually, it doesn't explain how to trigger a process with a document upload (linked to the process Contract). If anybody has a clear explanation on that, it would be of great help.

Submitted by bastien.laurent... on Mon, 08/19/2019 - 08:50

I have allready do that job in process.
Now, i just want to do the same job with JAVA API only.
In my case, i have a bonita process with an initialisation form who contain a file (Document).
So i want to initialise my process trough a JAVA API for including the process initialisation to my web application.

2 answers



I am not familiar with OKHttp but given the response you get (200 with nothing in the body), my guess would be that the content of the file is not sent or rather not sent as Multipart.
Maybe you need to use OKHttp's MultipartBuilder rather tan RequestBuilder.

Hope that helps


My case is a little different. I try to start a process which has a contract defining a document (defined at pool and lane levels). The actor is defined. It works perfect through the portal forms but I can't manage to trigger the process through the REST API. I studied the URLs used by the forms but they are not using the REST bpm/case API. So I am stuck...