Skip to content

LambdaHandler.fromHttpApi - Binary response #177

@florianbepunkt

Description

@florianbepunkt

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

export const isContentTypeBinary = (contentType: string) => {
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions