Skip to content

Commit 52f77d2

Browse files
committed
storage: add support for generation on getSignedUrl
1 parent a3ed900 commit 52f77d2

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/storage/file.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,7 @@ File.prototype.getSignedUrl = function(options, callback) {
11731173
}[options.action];
11741174

11751175
var name = encodeURIComponent(this.name);
1176+
var targetGeneration = this.generation;
11761177

11771178
options.resource = '/' + this.bucket.name + '/' + name;
11781179

@@ -1221,13 +1222,19 @@ File.prototype.getSignedUrl = function(options, callback) {
12211222
encodeURIComponent(options.responseDisposition);
12221223
}
12231224

1225+
var generation = '';
1226+
if (!is.undefined(targetGeneration)) {
1227+
generation = '&generation=' + targetGeneration;
1228+
}
1229+
12241230
callback(null, [
12251231
'https://storage.googleapis.com' + options.resource,
12261232
'?GoogleAccessId=' + credentials.client_email,
12271233
'&Expires=' + expiresInSeconds,
12281234
'&Signature=' + encodeURIComponent(signature),
12291235
responseContentType,
1230-
responseContentDisposition
1236+
responseContentDisposition,
1237+
generation
12311238
].join(''));
12321239
});
12331240
};

test/storage/file.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,18 @@ describe('File', function() {
17491749
});
17501750
});
17511751

1752+
it('should add generation parameter', function(done) {
1753+
var generation = 10003320000;
1754+
var file = new File(BUCKET, 'name', { generation: generation });
1755+
file.getSignedUrl({
1756+
action: 'read',
1757+
expires: Date.now() + 5,
1758+
}, function(err, signedUrl) {
1759+
assert(signedUrl.indexOf(encodeURIComponent(generation)) > -1);
1760+
done();
1761+
});
1762+
});
1763+
17521764
describe('promptSaveAs', function() {
17531765
it('should add response-content-disposition', function(done) {
17541766
var disposition = 'attachment; filename="fname.ext"';

0 commit comments

Comments
 (0)