Hello there, payload newbie here.
I'm filling out my schema at the moment and trying to figure out how to post a new document that contains JSON and an image file.
Here's the ArtistProfile.ts:
import { CollectionConfig } from 'payload/types';
const ArtistProfiles: CollectionConfig = {
slug: 'artistprofiles',
auth: false,
fields: [
{
name: "name",
type: "text",
required: true,
unique: true
},
{
name: "mainImage",
type: "upload",
required: true,
relationTo: 'mainimage',
unique: true
}
],
};
And MainImage.ts:
import { CollectionConfig } from 'payload/types';
const MainImage: CollectionConfig = {
slug: 'mainimage',
auth: false,
access: fullAccess,
fields: [{
name: "alt",
type: "text"
}],
upload: {
staticURL: '/mainimage',
staticDir: 'mainImage',
adminThumbnail: 'thumbnail',
mimeTypes: ['image/*'],
}
};
And I end up with [01:53:29] ERROR (payload): ValidationError: The following field is invalid: mainImage
Is there something I'm missing? Or is payload not built to support this? The alternative of course is to make separate requests, one to create the image in mainImage and then the artistProfile with a reference to the mainImage.