Skip to content

saveRequestFiles is consuming value fields and give no way to retreive them if there were no files #549

Open
@dzek69

Description

@dzek69

Prerequisites

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

Fastify version

3.20.x

Plugin version

6.0.1

Node.js version

21.7.1

Operating system

Linux

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

Alpine 3.15 I think

Description

I have a endpoint, where I process optional files. I really like the convenience of saveRequestFiles, but there is one problem - if there were no files - there is no way to access fields (I don't want to use attachFieldsToBody btw) - they are already consumed.

    // this prints "start" and "end" only

    const files = await req.saveRequestFiles();
    // `files` is  an empty array
    console.log("start");
    for await (const part of parts) {
        console.log(part);
    }
    console.log("end");

I know I can still do stuff manually, but maybe there is a way to improve saveRequestFiles somehow? Even "dumb" stuff like attaching extra fields property directly to an array returned by saveRequestFiles() would be nice (that would be non-breaking change)

Link to code that reproduces the bug

No response

Expected Behavior

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions