diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java index e0b78afc9292..bf46dac00740 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java @@ -306,7 +306,7 @@ public Blob updateBlob(String bucketName, String blobName) { } /** - * Example of udating a blob, only if the blob's metageneration matches a value, otherwise a + * Example of updating a blob, only if the blob's metageneration matches a value, otherwise a * {@link StorageException} is thrown. */ // [TARGET update(BlobInfo, BlobTargetOption...)] @@ -314,11 +314,13 @@ public Blob updateBlob(String bucketName, String blobName) { // [VARIABLE "my_blob_name"] public Blob updateBlobWithMetageneration(String bucketName, String blobName) { // [START updateBlobWithMetageneration] + Map newMetadata = new HashMap<>(); + newMetadata.put("key", "value"); Blob blob = storage.get(bucketName, blobName); - BlobInfo updatedInfo = blob.toBuilder().setContentType("text/plain").build(); - storage.update(updatedInfo, BlobTargetOption.metagenerationMatch()); + BlobInfo updatedInfo = blob.toBuilder().setContentType("text/plain").setMetadata(map).build(); + Blob updated=storage.update(updatedInfo, BlobTargetOption.metagenerationMatch()); // [END updateBlobWithMetageneration] - return blob; + return updated; } /**