Skip to content

Commit 420212a

Browse files
authored
feat: examples of creating a signed url for a blob with generation (#140)
* feat: examples of creating a signed URL for a blob with generation
1 parent 95e49a2 commit 420212a

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,21 +764,28 @@ public WriteChannel writer(BlobWriteOption... options) {
764764
* </ol>
765765
*
766766
* <p>Example of creating a signed URL for the blob that is valid for 2 weeks, using the default
767-
* credentials for signing the URL.
767+
* credentials for signing the URL:
768768
*
769769
* <pre>{@code
770770
* URL signedUrl = blob.signUrl(14, TimeUnit.DAYS);
771771
* }</pre>
772772
*
773773
* <p>Example of creating a signed URL for the blob passing the {@link
774-
* SignUrlOption#signWith(ServiceAccountSigner)} option, that will be used to sign the URL.
774+
* SignUrlOption#signWith(ServiceAccountSigner)} option, that will be used to sign the URL:
775775
*
776776
* <pre>{@code
777777
* String keyPath = "/path/to/key.json";
778778
* URL signedUrl = blob.signUrl(14, TimeUnit.DAYS, SignUrlOption.signWith(
779779
* ServiceAccountCredentials.fromStream(new FileInputStream(keyPath))));
780780
* }</pre>
781781
*
782+
* <p>Example of creating a signed URL for a blob generation:
783+
*
784+
* <pre>{@code
785+
* URL signedUrl = blob.signUrl(1, TimeUnit.HOURS,
786+
* SignUrlOption.withQueryParams(ImmutableMap.of("generation", "1576656755290328")));
787+
* }</pre>
788+
*
782789
* @param duration time until the signed URL expires, expressed in {@code unit}. The finer
783790
* granularity supported is 1 second, finer granularities will be truncated
784791
* @param unit time unit of the {@code duration} parameter

google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2483,7 +2483,7 @@ Blob create(
24832483
* }</pre>
24842484
*
24852485
* <p>Example of creating a signed URL passing the {@link
2486-
* SignUrlOption#signWith(ServiceAccountSigner)} option, that will be used for signing the URL.
2486+
* SignUrlOption#signWith(ServiceAccountSigner)} option, that will be used for signing the URL:
24872487
*
24882488
* <pre>{@code
24892489
* String bucketName = "my-unique-bucket";
@@ -2498,6 +2498,19 @@ Blob create(
24982498
* <p>Note that the {@link ServiceAccountSigner} may require additional configuration to enable
24992499
* URL signing. See the documentation for the implementation for more details.
25002500
*
2501+
* <p>Example of creating a signed URL for a blob with generation:
2502+
*
2503+
* <pre>{@code
2504+
* String bucketName = "my-unique-bucket";
2505+
* String blobName = "my-blob-name";
2506+
* long generation = 1576656755290328L;
2507+
*
2508+
* URL signedUrl = storage.signUrl(
2509+
* BlobInfo.newBuilder(bucketName, blobName, generation).build(),
2510+
* 7, TimeUnit.DAYS,
2511+
* SignUrlOption.withQueryParams(ImmutableMap.of("generation", String.valueOf(generation))));
2512+
* }</pre>
2513+
*
25012514
* @param blobInfo the blob associated with the signed URL
25022515
* @param duration time until the signed URL expires, expressed in {@code unit}. The finest
25032516
* granularity supported is 1 second, finer granularities will be truncated

0 commit comments

Comments
 (0)