现在可以在 keystone 的最新主分支中进行图像预览(请参阅 https://github.com/keystonejs/keystone/pull/4509)。目前你需要依赖keystone的git版本,所以把它放在你的package.json并运行npm install:
"keystone": "https://github.com/keystonejs/keystone.git"
在您的模型中,在相关图像字段中指定 thumb: true。您还需要架构中的 url 属性。例如:
const storage = new keystone.Storage({
adapter: keystone.Storage.Adapters.FS,
fs: {
path: keystone.expandPath('./uploads/images'),
publicPath: '/images/'
},
schema: {
url: true,
}
})
ImageUpload.add({
name: { type: Types.Key, index: true },
image: {
type: Types.File,
storage: myStorage,
thumb: true
},
createdTimeStamp: { type: String }
});
管理 UI 现在应该显示图像的小预览和指向它的链接。