I have such a collection schema configured
// Models collection schema
const Models: CollectionConfig = {
slug: 'models',
fields: [
{
name: 'fullname',
type: 'text',
required: true,
},
{
name: 'images',
type: 'array',
label: 'Images',
fields: [
{
name: 'src',
type: 'upload',
relationTo: 'media',
required: true,
},
]
},
],
But I can't figure out how to populate the images from the Local API create call. I'd really appreciate any help with this.
// Somewhere in the seeding task
type File = {
data: Buffer;
mimetype: string;
name: string;
size: number;
}
const uploaded: File = await fetchFromUrl(payload, url) // Returns File with Buffer
const model = await payload.create({
collection: 'models',
data: {
fullname: 'Name',
gender: 'female',
// Here it fails
// ↓↓↓↓↓↓
// ↓↓↓↓↓↓
images: [{ data: {}, file: uploaded }]
// ↑↑↑↑↑↑
// ↑↑↑↑↑↑
}
})
I'm having a similar problem.
You need to create the images in your uploads collection and then pass the id(s) from those created uploads to the field on your models collection.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.