Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

The following field is invalid: filename

default discord avatar
bumblebee9992 years ago
5

on create new post or duplicate it throws error ("The following field is invalid: filename")


const Posts: CollectionConfig = {
    slug: 'posts',
    admin: {
        defaultColumns: ['title', 'author', 'category', 'tags', 'status'],
        useAsTitle: 'title',
    },
    access: {
        create: () => true,
        read: () => true, //isAdminOrSelf,
        delete: isAdminOrSelf,
        update: isAdminOrSelf
    },
    fields: [
       ...
        {
            type: 'tabs',
            tabs: [
                {
                    label: 'Hero',
                    description: 'This will appear within the tab above the fields.',
                    fields: [
                        {
                            name: 'title',
                            type: 'text',
                            required: true,
                        },
                        {
                            name: 'slug',
                            label: 'Slug',
                            type: 'text',
//                            required: true,
                            unique: true,
                            admin: {
                                position: 'sidebar',
                            },
                            hooks: {
                                beforeValidate: [
                                    formatSlug('title'),
                                ],
                            },
                        },
                        {
                            name: 'postImage',
                            type: 'upload',
                            relationTo: 'media',
                            required: true,
                        }

                    ]
                },
            ]
        },
    ],
}
  • default discord avatar
    nacho001622 years ago

    Hey there! I'm having the same problem

  • default discord avatar
    bumblebee9992 years ago
    @281120856527077378

    I just upgrade payload 1.5.9 but same problem, when posts is empty and create new, it works fine, but after, even duplicate any post or adding new one, then throw me this error. 🤷🏼



    @281120856527077378

    same error on create or duplicate post, i don't have a field named "filename",


    {
        "errors": [
            {
                "name": "ValidationError",
                "message": "The following field is invalid: filename",
                "data": [
                    {
                        "message": "Value must be unique",
                        "field": "filename"
                    }
                ]
            }
        ]
    }


    I found something in codebase and I tried to drop all collection from MongoDB and now it works fine 🥳


     // Handle uniqueness error from MongoDB
          throw error.code === 11000 && error.keyValue
            ? new ValidationError([{ message: 'Value must be unique', field: Object.keys(error.keyValue)[0] }], t)
            : error;
  • default discord avatar
    zakoul2 years ago
    @281120856527077378

    Unfortunately I'm still encountering this issue with Payload v1.6.28 :/ Uploading works fine, but when I try to add a relationship on an "Upload" type field, I get the same error message

  • default discord avatar
    stefvw932 years ago
    @281120856527077378

    I also have this issue on 1.6.32

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.