不能过期使用node.js创build的Google云存储对象的SignedURL
使用node.js创buildGoogle云存储对象的signedURL
这是我的代码
var crypto = require("crypto"); var fs = require("fs"); var expiry = new Date().getTime() + 3600; var key = 'the_target_file'; var bucketName = 'bucket_name'; var accessId = 'my_access_id'; var stringPolicy = "GET\n" + "\n" + "\n" + expiry + "\n" + '/' + bucketName + '/' + key; var base64Policy = Buffer(stringPolicy, "utf-8").toString("base64"); var privateKey = fs.readFileSync("gcs.pem","utf8"); var signature = encodeURIComponent(crypto.createSign('sha256').update(stringPolicy).sign(privateKey,"base64")); var signedUrl = "https://" + bucketName + ".commondatastorage.googleapis.com/" + key +"?GoogleAccessId=" + accessId + "&Expires=" + expiry + "&Signature=" + signature; console.log(signedUrl);
它的工作正常。 但如何将失效时间缩短至10秒或其他。
下面的代码现在给我正确的输出。
var crypto = require("crypto"); var fs = require("fs"); var URL_VALID_DURATION = 1000 * 10;//for 10 seconds var expiry = Math.floor(((new Date).getTime() + URL_VALID_DURATION) / 1000); var key = 'the_target_file'; var bucketName = 'bucket_name'; var accessId = 'my_access_id'; var stringPolicy = "GET\n" + "\n" + "\n" + expiry + "\n" + '/' + bucketName + '/' + key; var base64Policy = Buffer(stringPolicy, "utf-8").toString("base64"); var privateKey = fs.readFileSync("gcs.pem","utf8"); var signature = encodeURIComponent(crypto.createSign('sha256').update(stringPolicy).sign(privateKey,"base64")); var signedUrl = "https://" + bucketName + ".commondatastorage.googleapis.com/" + key +"?GoogleAccessId=" + accessId + "&Expires=" + expiry + "&Signature=" + signature; console.log(signedUrl);
- 如何使用Node.js将base64编码图像(string)直接上传到Google Cloud Storage存储桶?
- 从Google云端存储中读取图片,并使用Google云端function进行发送
- 同样的Google云端存储上传脚本可以在一台电脑上运行,但是不能运行,为什么?
- Google云端存储似乎忽略了客户提供的encryption密钥标头
- Google Storage nodejs上传MIME TYPE
- 如何从服务器上的客户端JavaScript上载到Google云端存储?
- 如何在Node.js中使用bigquery API获取800万条Google Cloudlogging?
- Google云端存储忽略分隔符
- Node.jsstream直接上传到Google云端存储