Skip to content

ContentTypeParser Image regrex failed to capture any image type when router added #4495

@anilkumarum

Description

@anilkumarum

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.11.0

Plugin version

No response

Node.js version

19.x

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

linux mint

Description

I try to add custom parser to parse all image files.
I copy image content parser code from fastify documentation but fail to capture any image format.
This code throw error:
FastifyError: Unsupported Media Type: image/jpeg\n at ContentTypeParser.run.

fastify.addContentTypeParser(/^image\/.*/, { parseAs: "buffer" }, (req, payload, done) => {
	done(null, payload)
});

But when i remove regrex and add hardcoded image format then no error thrown and image parsed successfully.
This code work:

fastify.addContentTypeParser("image/png", { parseAs: "buffer" }, (req, payload, done) => {
	done(null, payload)
});

Steps to Reproduce

fastify.addContentTypeParser(/^image\/.*/, { parseAs: "buffer" }, (req, payload, done) => {
  done(null, payload);
});

Expected Behavior

I want to capture all image mime type format.
Suggested regrex must work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions