How to return binary data through REST API extension?

Hello,

I'm trynig to make a process which involves file handling (uploading files in a case to be downloaded in a later case by a separate user) and prepared everything by consuming the file input from the uploading case in an out connector that uploads the raw binary content to a separate service that is on localhost only. However now on the downloading side I'm trying to implement this using a REST API extension, since I want to be able to verify the accessing user before letting them download the file from the separate service.

So for the downloader this is my code so far:

logger.info("Downloading file $uuid in activity ${activity.name} (ID: $activityId)")
val client = newBuilder()
    .version(Version.HTTP_1_1)
    .followRedirects(Redirect.NEVER)
    .connectTimeout(Duration.ofSeconds(20))
    .build()

val request = HttpRequest.newBuilder()
    .uri(URI.create("$serviceHost/file/$uuid"))
    .timeout(Duration.ofMinutes(1))
    .GET()
    .build()

val res = client.send(request, BodyHandlers.ofByteArray())
return responseBuilder
    .withResponseStatus(res.statusCode())
    .withMediaType(
        res.headers().firstValue("Content-Type").orElse("application/octet-stream")
    )
    .withResponse(res.body())
    .build()

However the withResponse API takes in a "Serializable", indicating I can only really pass through Strings, since the Java serialization format for complex objects is otherwise useless outside the Java ecosystem.

Also since the RestApiResponseBuilder contains a withCharacterSet, indicating it can only describe text, I don't think it's the right API for me to use when I want to send out binary and would probably need some kind of binary response builder instead.

I looked online for this and found in https://community.bonitasoft.com/questions-and-answers/how-can-i-return-binary-data-part-rest-extension that this wasn't possible 3 years ago, but there was an idea board linked that now doesn't seem to exist anymore / require some login now. Did anything there change to make it now possible?

My alternatives right now are either making another service / extending the file upload service with some temporary public sharing that can be triggered from my REST API extension, which is a lot of extra administration and security overhead with making a public facing service or alternatively encode the binary file to a string using e.g. Base64, and decode in the browser, which seems super inefficient and wasteful for the simple task at hand.

Any ideas how to solve this? Is my file handling approach itself fundamentally flawed? I'm only doing all this extra work with a separate file hosting service since it looks like Bonita is unable to store the files anywhere outside a single task, specifically not inside the BDM.

Kind regards,
Jan

A lamp with a remote control adds a modern touch to your home decor. These  lamp with control remote lamps are often designed with sleek, contemporary aesthetics in mind, making them a stylish addition to any room.

Homeowners in Edmonton recognize the value of investing in high-quality soffit installation to protect their  soffit installation edmonton properties from environmental factors and ensure long-term durability. Beyond functionality, soffits contribute to the overall aesthetic appeal of homes.

Prevents overal location or underutilization by providing a clear overview of resource allocation and availability these  small business management software systems help businesses plan more effectively, reduce costs, and enhance productivity.

With real-time updates and notifications, you'll never miss a payment deadline again. Plus, Boost Mobile's secure payment gateway boost mobile pay my bill ensures that your financial information remains protected at all times, giving you peace of mind with every transaction.

But also ensures long-lasting comfort and support, thanks to the innovative technology embedded in design. This blend of luxury and functionality makes the Louis Vuitton Air Force 1 a must-have for those who appreciate the finer things in life.

Another notable benefit of trucker cap is their durability and longevity. Constructed with sturdy materials like cotton twill, polyester, and mesh, these caps are built to withstand the rigors of daily wear and tear.

Proper storage of tirzepatide is essential to maintain its effectiveness. Store the pen in the refrigerator at  how to inject tirzepatide compound a temperature between 36°F to 46°F (2°C to 8°C). Do not freeze tirzepatide or expose it to direct sunlight or high temperatures.

They ensure that every dollar spent delivers maximum value and ROI. Partnering with an affordable agency allows business owners to focus on growing top marketing agency flower mound their business while leaving the marketing complexities to the experts, making it a smart choice for long-term success.