Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation doesn't work for application/octet-stream #932

Open
Lutymane opened this issue Dec 3, 2024 · 0 comments
Open

Validation doesn't work for application/octet-stream #932

Lutymane opened this issue Dec 3, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Lutymane
Copy link

Lutymane commented Dec 3, 2024

What version of Elysia is running?

1.1.25

What platform is your computer?

WSL2 Ubuntu under Windows 11

What steps can reproduce the bug?

Server:

import { Elysia, t } from "elysia";

new Elysia().post("/test", ({ body }) => {
    // prints proper ArrayBuffer if validation is commented out
    console.log(body)
}, {
  body: t.Uint8Array(),
});

Client:

await fetch("/test", {
  method: "POST",
  body: new Uint8Array([1, 2, 34, 52, 8]),
  headers: { "content-type": "application/octet-stream" },
});

When validation is present it errors with default 422 "Unprocessable Entity" message, if validation is commented out the payload is properly passed as body field

What is the expected behavior?

It shouldn't error and properly do the check

What do you see instead?

No response

Additional information

Fortunately I found a workaround for this with using onTransform hook:

import { Elysia, t } from "elysia";

new Elysia().post(
  "/test",
  ({ body }) => {
    // prints proper ArrayBuffer if validation is commented out
    console.log(body);
  },
  {
    transform(ctx) {
      if (ctx.body instanceof ArrayBuffer) {
        ctx.body = new Uint8Array(ctx.body);
      }
    },
    body: t.Uint8Array(),
  }
);

Have you try removing the node_modules and bun.lockb and try again yet?

yes

@Lutymane Lutymane added the bug Something isn't working label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant