好吧,我终于想通了。在玩了很长时间的随机猜谜游戏之后,我心想
“也许我需要签署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);};希望这会帮助遇到相同问题的其他人。



