I am passing an encoded file as a http:Request request
for a ballerina REST service. I need to decode the binary payload of the request
using Base64
in order to upload it to a file server. I was unable to find a way to decode a byte[]
using Base64
. Here is my sample code.
resource function post\-file(http:Request request) returns string|error {
byte[]|http:ClientError binaryPayload = request.getBinaryPayload();
if binaryPayload is http:ClientError {
return error("Error in payload");
}
// Now I need to decode the binaryPayload into a byte[]
// Tried following options. But seems like those options are not available in Swan Lake Update 3
// byte[] decodedPayload = check encoding:base64Decode(binaryPayload);
// byte[] decodedPayload = io:base64Decode(encodedPayload);
// How to do this in a correct way?
return "success";
}
How can I do this ?