使用s3存储桶通过表单的Keystone文件

时间:2017-01-16 08:02:49

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

当我尝试将其上传到亚马逊s3存储桶时,文件上传无法通过keystone中的表单工作 我正在使用keystone 0.4.0 beta版本和jade。

这是我的模特

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将我的文件移动到亚马逊桶...... ??

1 个答案:

答案 0 :(得分:0)

也许您从路由/ js代码中引用它,但据我所知,您调用文件" cvName"以你的玉石形式,但在你的模型中,你称之为"文件"。如果您没有明确重命​​名或将其分配到路径文件中,则它不知道您要保存在模型中的文件"文件"字段。