Not possible to have an upload to be optional, is it a bug?

default discord avatar
hunghvu
last year
1 1

When I test the upload feature, it seems like an upload field is not optional. For example,

import { CollectionConfig } from "payload/types";

const Test:CollectionConfig = {
  slug: 'tests',
  fields: [
      {
        name: 'metaCoverImage',
        label: 'Cover Image',
        type: 'upload',
        relationTo: 'media',
        required: true,
      },
      {
        name: 'metaCustomOgImage',
        label: 'Custom OG Image (front-end will fallback to cover image if not presented)',
        type: 'upload',
        relationTo: 'media',
      },
    ]
}

export default Test;

The second upload field should be optional, however, it raises an exception when no upload is presented. Is this a design decision or a bug? If it is a design decision, then is there a way to have an optional upload?

image

  • discord user avatar
    DanRibbens
    Payload Team
    last year

    Hey @hunghvu, it looks like a regression from the changes we made to futher validate upload and relationships. I'll get a fix out soon!

    2 replies
  • discord user avatar
    DanRibbens
    Payload Team
    last year

    OK, this is fixed now, please upgrade to v1.0.30.

    Thanks for asking or I wouldn't have caught it!

  • default discord avatar
    hunghvu
    last year

    Can confirm that it was fixed. I always love this lightning-fast response from the team. Keep up the great work!

Open the post
Continue the discussion in GitHub
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.