payloadcms / payloadcms/payload

Multipart Form-Data Upload Fails with 'Cannot read properties of undefined (reading 'firstName')' in Tests Collection

Open
#11,397 2 comments 0 reactions 1 assignee View on GitHub

@PatrikKozak is already working on this.

Since Feb 26, 2025.

area: docs
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

Description:
I’m experiencing an issue when trying to create a document in the tests collection via REST API using multipart/form-data to upload an image along with text fields (firstName, lastName, user). The request works fine when using JSON with just the media ID, but fails with the error Cannot read properties of undefined (reading 'firstName') when I send a file directly.

Steps to Reproduce:

  1. Set up a tests collection with the following configuration:
    import { type CollectionConfig } from "payload";
    
    export const Tests: CollectionConfig = {
      slug: "tests",
      fields: [
        { name: "firstName", type: "text" },
        { name: "lastName", type: "text" },
        { name: "user", type: "relationship", relationTo: "users" },
        { name: "image", type: "upload", relationTo: "media", required: true },
      ],
    };
    
    
    
    

*** I have this collection and I want to make a post request with the api/test path.
I did the test in my postman:
1- Body: If I send the data in the body format, i.e. as follows, the request is done correctly (in this method, the file is uploaded first and its ID is placed in the request)
{
"lastName": "test new",
"firstName": "me",
"image": "67bed87ed05f4b76c53e2bde"
}

2- form-data: If I want to send the request in the multiform method, i.e. send the file, the server side returns an error:

Req:
Image
err:
Cannot read properties of undefined (reading 'firstName')

Does the payload have a method for what I want (sending a file to the desired collection) or not?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.