Skip to Page Navigation Skip to Page Navigation Skip to Content
Keystone 6
Blog Enterprise β†— Docs

File

A file field represents a file of any type.

See the Images and Files guide for details on how to configure storage for the file field type.

import{ config, list }from'@keystone-6/core';
import{ file }from'@keystone-6/core/fields';
import fs from'node:fs/promises';
exportdefaultconfig({
lists:{
SomeListName:list({
fields:{
repo:file({
storage:{
asyncput(key, stream){
await fs.writeFile(`public/files/${key}`, stream)
},
asyncdelete(key){
await fs.unlink(`public/files/${key}`)
},
url(key){
return`http://localhost:3000/files/${key}`
},
},
}),
/* ... */
},
}),
/* ... */
},
/* ... */
});

Options:

  • storage(required): An object that defines how to upload (put), delete (delete) and get a URL to the file (url).

On this page

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /