【发布时间】:2014-10-15 09:02:13
【问题描述】:
我正在尝试创建一个用于上传到亚马逊 s3 的 S3 策略...但是在对策略进行编码时,我收到一个类型错误:不是缓冲区。我正在使用加密版本:0.0.3 和 aws-sdk 版本:2.0.0-rc.19
这之前有效,所以我认为它可能与 aws-sdk 的更新有关...
这里是代码。注释将显示错误发生的位置:
createS3Policy = function(contentType, callback) {
var date = new Date();
var s3Policy = {
'expiration': getExpiryTime(),
'conditions': [
['starts-with', '$key', 'shimmy-assets/'],
{'bucket': S3_BUCKET},
{'acl': 'public-read'},
['starts-with', '$Content-Type', contentType],
{'success_action_status' : '201'}
]
};
// stringify and encode the policy
var stringPolicy = JSON.stringify(s3Policy);
console.log('string policy: ' + stringPolicy);
var base64Policy = new Buffer(stringPolicy, 'utf-8').toString('base64');
// sign the base64 encoded policy
// NOT A BUFFER ERROR HERE
var signature = crypto.createHmac('sha1', AWS_SECRET_KEY).update(new Buffer(base64Policy, 'utf-8')).digest('base64');
// build the results object
var s3Credentials = {
s3Policy: base64Policy,
s3Signature: signature,
AWSAccessKeyId: AWS_ACCESS_KEY
};
// send it back
callback(s3Credentials);
};
【问题讨论】:
-
AWS_SECRET_KEY的定义是什么?是Buffer吗?
标签: node.js amazon-web-services amazon-s3