【问题标题】:URL not saved in File Field objectURL 未保存在文件字段对象中
【发布时间】:2018-10-18 12:56:14
【问题描述】:

我已使用文件字段上传文件,它工作正常,但文件 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 }
});

谢谢

【问题讨论】:

    标签: node.js keystonejs


    【解决方案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,
        },
    });
    

    【讨论】:

      猜你喜欢
      • 2016-06-20
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-21
      • 2018-07-20
      • 2011-02-25
      • 2011-01-16
      相关资源
      最近更新 更多