fastify / fastify/fastify-multipart

Strange behaviour with request.file() when filename in form is not specified

Open
#504 3 comments 1 reaction 0 assignees View on GitHub
bug discussion
Dominant language
JavaScript
Stars
539
Forks
126
PR merge metrics
No merged PRs in 30d

Description

### Prerequisites

- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported

### Fastify version

4.23.2

### Plugin version

8.1.0

### Node.js version

20.x

### Operating system

macOS

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

Sonoma 14.2

### Description

I encountered a strange behavior in the `request.file()` method when I send a multipart (using `form-auto-content`) without specifying the `filename` of the sent file. The method returns `undefined`. I do not know if it is a `form-auto-content` issue, if this is the expected behaviour or not. If it is expected I'll close this.

### Steps to Reproduce

Reproduction example: https://codesandbox.io/p/devbox/fastify-multipart-filename-nxnqgd

- Setup a fastify server with the `@fastify/multipart` plugin with a route calling `req.file()`
- Setup a simple client using `form-auto-content` and appending a file specifying the `contentType` but not the `filename`
- Call the endpoint

### Expected Behavior

I expect an error (if multipart with part missing the filename are considered malformed) or otherwise the parsed file.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.