0

I am trying to return a byte array result from a generated excel file on the back-end. I want to send it to the React front-end to automatically download after the redirect. I have been trying to do something like this, but with no success, because the Javalin documentation is very poor and it's very hard to find resources online:

import io.javalin.http.Context;

...

public JSONObject handle(HandlerPayload handlerPayload, Context ctx) throws EndpointException {
    
    JSONObject result = new JSONObject();

    ...
    
    byte[] excel_bytes = GenerateExcel();

    ctx.result(excel_bytes);
    ctx.redirect("/#/download_file", HttpStatus.FOUND_302);

    return result;
}

Any suggestion is very welcomed. Thank you!

Emi
  • 1,165
  • 4
  • 15
  • 26

0 Answers0