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

Multipart and body parsers #308

Open
furanzujin opened this issue Apr 13, 2022 · 3 comments
Open

Multipart and body parsers #308

furanzujin opened this issue Apr 13, 2022 · 3 comments

Comments

@furanzujin
Copy link
Contributor

furanzujin commented Apr 13, 2022

Hello @icebob,

In the File upload aliases section of the documentation, a note indicates that:

Please note, you have to disable other body parsers in order to accept files.

As we need to use both multipart and the JSON body parser on the same route, we experimented a bit with this use case on an auto-aliased route.

Moleculer web routes settings

{
  routes: [
    {
      path: '/',
      whitelist: buildWhitelist(),
      mappingPolicy: 'restrict',
      authorization: true,
      authentication: true,
      autoAliases: true,
      bodyParsers: {
        json: true,
      },
      aliases,
    },
    ...otherRoutes,
  ],
}

Service definition

{
  name: 'poc',
  actions: {
    multipart: {
      rest: {
        method: 'POST',
        path: 'multipart/:id',
        type: 'multipart',
        authentication: false,
        authorization: false,
      },
      handler: multipartHandler,
    },
    stream: {
      rest: {
        method: 'POST',
        path: 'stream/:id',
        type: 'stream',
        authentication: false,
        authorization: false,
      },
      handler: streamHandler,
    },
    standard: {
      rest: {
        method: 'POST',
        path: 'standard/:id',
        authentication: false,
        authorization: false,
      },
      handler: standardHandler,
    },
  },
}

Using the above configurations, it appeared that the three types of routes (standard, multipart, and stream) work together on the same route despite the documentation note.

It is quite good news for us but is this behavior expected to last in further versions?
In this case, shall we create a pull request to fix the documentation?

NOTE: also the documentation (Multipart parameters) indicates the ctx.params.$params contains parameters from URL querystring, though it appears they are in ctx.meta.$params instead.

@icebob
Copy link
Member

icebob commented Apr 19, 2022

Hmm, it looks parser's conflict is solved by time.

Yes, please create a PR with the fixes. Thanks in advance!

@furanzujin
Copy link
Contributor Author

As good as done.

Though we made a few more tests to double-check the behavior.
It appears that we cannot receive the content-disposition headers provided in each multipart file section.
Is there any way to retrieve this information?

furanzujin added a commit to furanzujin/site that referenced this issue Apr 20, 2022
@icebob
Copy link
Member

icebob commented Apr 23, 2022

I have no idea. You can check the busboy source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants