栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Amazon S3 POST api,并使用NodeJS签名策略

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Amazon S3 POST api,并使用NodeJS签名策略

好吧,我终于想通了。在玩了很长时间的随机猜谜游戏之后,我心想

“也许我需要签署base64编码策略”-我

BAM 就是这样。

我还重新排列了条件以匹配表单的发布方式,尽管我不确定这会有所不同。

var crypto = require("crypto");var config = require("../../amazonConfig.json");exports.createS3Policy = function(contentType, callback) {  var date = new Date();  var s3Policy = {    "expiration": "2014-12-01T12:00:00.000Z", // hard pred for testing    "conditions": [      ["starts-with", "$key", "somefolder/"],       {"bucket": "my-bucket-name"},       {"acl": "public-read"},       ["starts-with", "$Content-Type", contentType],      {"success_action_redirect": "http://example.com/uploadsuccess"},    ]  };  // stringify and enpre the policy  var stringPolicy = JSON.stringify(s3Policy);  var base64Policy = Buffer(stringPolicy, "utf-8").toString("base64");  // sign the base64 enpred policy  var signature = crypto.createHmac("sha1", config.secretKey)    .update(new Buffer(base64Policy, "utf-8")).digest("base64");  // build the results object  var s3Credentials = {    s3Policy: base64Policy,    s3Signature: signature  };  // send it back  callback(s3Credentials);};

希望这会帮助遇到相同问题的其他人。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/417996.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号