REST API Extension

1
0
-1

Hi, i would like to create REST API Extension for Bonita that can return file (to download). I stores files on a server machine and on call GET MyRestApiExtension Service i would like to server file, that can be download. On RestApiResponseBuilder i set mediaType n application/octet-stream and i also add additional header "Content-Disposition" but i have problem to server files bytes to response.

Have anyone do this or is it even posible.

Comments

Submitted by antoine.mottier on Tue, 02/12/2019 - 19:33

To make sure that I answer correctly, can you confirm that:

  1. Your file is stored on the file system of the server where Bonita web application is deployed?
  2. That you want the user to be able to download the file from a Bonita form?

Thanks

Submitted by krzysztof.gemse... on Tue, 02/12/2019 - 19:40

Hi, thank you for interest about my topic.

1. Yes, the file can be stored for example on the server filesystem.

2. Yes, for example on Bonita Application Page.

1 answer

1
+1
-1

I dig on your use case and actually found a limitation of the REST API extension. Currently (in Bonita 7.8.2 and previous versions) a REST API extension can only returns a response with text body. It is not possible to return octect streams that is required to be able to download all types of files.

I can post here the code that will let the user download any text files:

def absoluteFilePathAsString = request.getParameter "absoluteFilePath"
if (absoluteFilePathAsString == null) {
    return buildResponse(responseBuilder, HttpServletResponse.SC_BAD_REQUEST,"""{"error" : "the parameter absoluteFilePath is missing"}""")
}

def path = Paths.get(absoluteFilePathAsString)
responseBuilder.withResponseStatus(HttpServletResponse.SC_OK).
withMediaType('application/octet-stream').
withAdditionalHeader('Content-Disposition', "attachment; filename=${path.fileName}").
withResponse(path.toFile().text).
build();

So to answer your need I can see two options:

  • You can declared in your process definition "documents" and initialize them using the file content available on the server (or directly embedded the file in the process definition). Then you can add download link in Bonita forms for document.
  • You can setup a web server (e.g. Apache HTTPD) to serve the file and includes links in the Bonita forms.

Regards

Notifications