LambdaHandler.fromHttpApi - Binary response
I'm struggling with a binary response in an HttpAPI.
My endpoint is this
const CreateSetEndpoint = HttpApiEndpoint.post("createSet", "/create-set").addSuccess(
Schema.Uint8ArrayFromSelf.pipe(
HttpApiSchema.withEncoding({
kind: "Uint8Array",
contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
})
)
);
// implementation is type-safe, so omited for brevity
export const handler = LambdaHandler.fromHttpApi(
Layer.mergeAll(HeraklesApiLive, HttpServer.layerContext)
);
I can compile and deploy it as a HttpApi. Calls to the endpoint return a file, but the file is corrupted. I checked the business logic which works fine, so the problem must happen somewhere on the API side.
I checked the tests and there is no test for binary responses at the moment. When checking the code I was wondering whether the logic here is correct https://github.com/floydspace/effect-aws/blob/92a98b16f412edb4a74708fe19e5aa8daf96dd11/packages/lambda/src/LambdaHandler.ts#L291C1-L293C49
If so, then the check here https://github.com/floydspace/effect-aws/blob/92a98b16f412edb4a74708fe19e5aa8daf96dd11/packages/lambda/src/internal/utils.ts#L107 should return true for "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" which is the mime type of an excel file. But it returns false, which I guess is the root issue here.
Hey @florianbepunkt
it is indeed matching the regex
could you pls try application/octet-stream to confirm your hypothesis
PS I copied that regex from hono, so could be the edge case for hono adapter too
@floydspace Yes, using application/octet-stream does work as intended.
~~Sidenote: Do you know whether we can set Response headers now with the HttpApiBuilder module? Was trying to set a Content-Disposition header for the response..~~ EDIT: Found it.