Binary data across Forge bridge

I am working on a Forge app where the CustomUI part of the app needs to request a binary file from the Server side. The documentation is not 100% clear on this, but from my experiments it seems that a) the response object is not exposed, and b) I can only return strings or JSON from a function registered with the resolver.

I would like to be able to do something similar to res.sendfile() or res.pipe(), like the following pseudo code.

resolver.define('getSomething', async (req, res) => {
  console.log(`req=${JSON.stringify(req)}`); <-- contains custom req object
  console.log(`res=${JSON.stringify(res)}`);  <-- is always 'undefined'

   res.sendFile('<somefile>');
});

Encoding the binary value as a string works but I soon hit the size limit for the response and the value gets truncated.

My workaround at the moment is to use an external service (an AWS Lambda function) to generate the binary data and call that from my CustomUI front-end. However, my customers are not happy with that solution as it means that end-user data is processed outside the Forge/Atlassian environment.

My question is two-fold: firstly (question to the community), are there any other ways of doing this without a remote server outside the Forge environment. And secondly (question for Atlassian), are there any plans to start supporting binary data across the Forge Bridge?

1 Like

Hey @muschol,
I looked at the resolver function signatures closely for my own development. It’s all TypeScript so it gives explicit description of what can be done.

interface ResponseObject {
    [key: string]: any;
}
declare type Response = ResponseObject | string | void;
declare type ResolverFunction = (request: Request) => Promise<Response> | Response;

The resolver function returns only a dictionary [key: string]: any; or a string.
Returning any type is done using a dict, usually as {value: <blob>}, but the binary object will nevertheless be serialized between the backend side of Forge and the frontend side. Don’t know much about the serialization/deserialization of the resolver (Any doc Atlassian ?).

For your second question, to store data within Atlassian you could use Entity properties/Content properties but they are limited in size.

3 Likes

Submitted a new suggestion: [FRGE-1439] - Ecosystem Jira

1 Like