【发布时间】: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