【问题标题】:Keystone file via form using s3 bucketKeystone 文件通过表单使用 s3 存储桶
【发布时间】:2017-05-31 00:32:26
【问题描述】:

当我尝试将文件上传到 Amazon s3 存储桶时,无法通过 keystone 中的表单进行文件上传 我正在使用带有jade的keystone 0.4.0 beta版本。

这是我的模特

var keystone = require('keystone');
var Types = keystone.Field.Types;
var Email = require('keystone-email');

  var storage = new keystone.Storage({
  adapter: require('keystone-storage-adapter-s3'),
  s3: {
    key: process.env.S3_KEY, 
    secret: process.env.S3_SECRET, 
    bucket: process.env.S3_BUCKET, 
    region: process.env.S3_REGION,
    path: '/cv',
    headers: {
      'x-amz-acl': 'public-read', // add default headers; see below for details
    },
  },
  schema: {
    bucket: true, // optional; store the bucket the file was uploaded to in your db
    etag: true, // optional; store the etag for the resource
    path: true, // optional; store the path of the file in your db
    url: true, // optional; generate & store a public URL
  },
});

  var Intern = new keystone.List('Intern',{
        nocreate: true,
        noedit: true,
 });

 Intern.add({
        name :{type: Types.Name , required:true},
        email: { type: Types.Email, required: true },
        phone: { type: String },
        qualification: {type:Types.Select, options:'Graduate, Post Graduate, UnderGraduate, Pursuing Graduation, Diploma, Others', default: 'Pursuing Graduation'},
        proficiency: {type:String},
        reason: {type: Types.Textarea, required: true},
        project: {type:String},
        createdAt: { type: Date, default: Date.now },
        file: { type: Types.File, storage: storage },
 });

我的玉码……

.col-sm-12
  form(method='post' enctype='multipart/form-data')
    input(type='hidden', name='action', value='intern')
    .col-sm-6
        .form-group
            label Upload CV
            input(type='file', id='cvId',  name='cvName').form-control      
            .form-actions
             button(type='submit').btn.btn-primary Send

还有js代码

我应该如何使用 updatehandler 将我的文件移动到亚马逊存储桶...??

【问题讨论】:

  • 您能否也提供路线中的代码,因为这是处理文件上传的部分。

标签: node.js file-upload amazon-s3 keystonejs keystone


【解决方案1】:

也许您从您的 route/js 代码中引用它,但据我所知,您在翡翠形式中将文件称为“cvName”,但在您的模型中,您将其称为“文件”。如果你没有在你的路由文件中明确地重命名或分配它,它不知道你要保存在模型的“文件”字段中的文件。

【讨论】:

    猜你喜欢
    • 2017-11-23
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多