Skip to content

Type value does not exist on MultipartFile when using onFile #574

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

Open
2 tasks done
mhamid3d opened this issue Mar 24, 2025 · 2 comments
Open
2 tasks done

Type value does not exist on MultipartFile when using onFile #574

mhamid3d opened this issue Mar 24, 2025 · 2 comments

Comments

@mhamid3d
Copy link

mhamid3d commented Mar 24, 2025

Prerequisites

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

Fastify version

5.2.1

Plugin version

9.0.3

Node.js version

23.7.0

Operating system

Windows

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

11

Description

When using onFile, the part does not have typings for value

So this code from the readme is not valid. As such I am providing this github repo as the reproducible example:

async function onFile(part) {
  const buff = await part.toBuffer()
  const decoded = Buffer.from(buff.toString(), 'base64').toString()
  part.value = decoded // set `part.value` to specify the request body value
}

fastify.register(require('@fastify/multipart'), { attachFieldsToBody: 'keyValues', onFile })

fastify.post('/upload/files', async function (req, reply) {
  const uploadValue = req.body.upload // access file as base64 string
  const fooValue = req.body.foo       // other fields
})

Link to code that reproduces the bug

https://github.com/fastify/fastify-multipart

Expected Behavior

Typings for value on MultipartFile

@mcollina
Copy link
Member

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

@mhamid3d
Copy link
Author

mhamid3d commented Apr 3, 2025

If using Typescript, this should produce an error on part.value

fasitfy.register(import('@fastify/multipart'), {
        attachFieldsToBody: 'keyValues',
        onFile: async (part) => {
            const buff = await part.toBuffer();
            part.value = buff.toString('base64');
        },
    });

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