URL未保存在“文件字段”对象中

时间:2018-10-16 07:10:26

标签: node.js keystonejs

我已经使用“文件字段”上传了文件,但工作正常,但文件URL未保存在数据库中。

文件对象

benifitsFile
Object:filename:
"srrfnKNvcQ1zTOup.pdf"
size:878742
mimetype:"application/pdf"

我必须定义一个存储路径并添加文件类型。

var Storagepath = new keystone.Storage({
  adapter: keystone.Storage.Adapters.FS,
  fs: {
    path: '/public/uploads',
        publicPath: '/public/uploads/',
  },
});

Course.add({
  title: { type: String, required: true, initial: true},
  headerimage: { type: Types.CloudinaryImage,label:'Header Image' },
  benifitsFile: { type: Types.File, storage: Storagepath ,label:'Upload features & benifits file'},
  questions: { type: Types.Relationship, ref: 'Question', index: true,many:true }
});

谢谢

1 个答案:

答案 0 :(得分:1)

最后,我找到了解决方案。

var Storagepath = new keystone.Storage({
  adapter: keystone.Storage.Adapters.FS,
  fs: {
    path: keystone.expandPath('./public/uploads'),
    publicPath: './public/uploads',
  },
  schema: {
    size: true,
    mimetype: true,
    path: true,
    originalname: true,
    url: true,
    },
});