The following field is invalid: filename

default discord avatar
bumblebee
4 months ago
7

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
    nacho
    4 months ago

    Hey there! I'm having the same problem

  • discord user avatar
    Jarrod
    Payload Team
    4 months ago
  • default discord avatar
    bumblebee
    4 months ago

    @Jarrod 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. 🤷🏼



    @Jarrod 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
    zakoul
    last month

    @Jarrod 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
    Stef
    last month

    @Jarrod I also have this issue on 1.6.32

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.