Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

478
Views
¿Cómo sembrar/cargar imágenes en KeystoneJS 6?

Usando el ejemplo aquí , si luego agrego un campo de imagen a Publicar:

 // 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(), }), /* ... */ }, /* ... */ });

¿Cómo puedo ajustar el archivo seed/index.ts para cargar una imagen desde el disco local?

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

O de lo contrario, ¿cómo puedo agregar imágenes mediante programación para que keystonejs las conozca?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Obtenido de aquí 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!