diff --git a/README.md b/README.md index 15f7857..faf7462 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,5 @@ var policy = myS3Account.writePolicy('myfile', 'mybucket', 60, 10); ```` * Website: http://www.arbitrarytech.com + +Please note that the key is optional on the readPolicy method. A key for the bucket only may be generated. \ No newline at end of file diff --git a/main.js b/main.js index 1ca9fa3..3a9a9c7 100644 --- a/main.js +++ b/main.js @@ -15,6 +15,11 @@ function s3instance(accessKey, secretKey) { expiration = Math.round(expiration.getTime() / 1000); var policy = 'GET\n\n\n' + expiration + '\n'; + policy += '/' + bucket; + if (key){ + policy += '/'; + policy += key; + } policy += '/' + bucket + '/' + key; if (download) { policy += '?response-content-disposition=attachment;filename=' + encodeURIComponent(download); @@ -23,8 +28,11 @@ function s3instance(accessKey, secretKey) { var signature = crypto.createHmac("sha1", this.secretKey).update(policy); var url = 'https://s3.amazonaws.com/'; - url += bucket + '/'; - url += key; + url += bucket; + if (key) { + url += '/'; + url += key; + } url += '?AWSAccessKeyId=' + this.accessKey; url += '&Expires=' + expiration; url += '&Signature=' + encodeURIComponent(signature.digest("base64"));