Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

481
Vistas
How to seed/upload images in KeystoneJS 6?

Using the example here, if I then add an image field to Post:

// schema.ts
import { list } from '@keystone-6/core';
import { select, relationship, text, timestamp } from '@keystone-6/core/fields';

export const lists = {
  Post: list({
    fields: {
       featureImage: image(),
    }),
    /* ... */
  },
  /* ... */
});

How can I then adjust the seed/index.ts file to upload an image form the local drive?

// seed/index.ts
await context.query.Post.createOne({
    data: {
        ...postData,
        featureImage: { /* ??? What goes here ??? */ }
    },
    query: 'id',
});

Or otherwise, how can I programmatically add images so that keystonejs is aware of them?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Got from here https://github.com/keystonejs/keystone-discussions-archive/discussions/54

// prepareToUpload.ts
import mime from 'mime'
import fs from 'fs'
import path from 'path'
import { Upload } from 'graphql-upload'

export const prepareToUpload = (filePath: string) => {
  const filename = path.basename(filePath)

  const createReadStream = () => fs.createReadStream(filePath)
  // @ts-ignore
  const mimetype = mime.getType(filePath)
  const encoding = 'utf-8'

  const image = {
    createReadStream,
    filename,
    mimetype,
    encoding,
  }

  const upload = new Upload()
  // @ts-ignore
  upload.resolve(image)

  return upload
}

  await context.query.Film.createOne({
      data: {
        name: filmData.name,
        imagePoster: {
          // imagePoster MUST by a object with `upload` field
          upload: prepareToUpload(__dirname + '/folder_to_local_file/here.jpg'),
        },
      },
      query: 'id',
    })
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda