Could'nt expire SignedURL of google cloud storage object created using node.js -


am creating signedurl of google cloud storage object using node.js.

this code

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); 

its working fine. how reduce expiry time 10 second or else.

the below code gives me correct output.

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); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -