From 0269dfa6a465825e62da7612fce9a6e953a9aeae Mon Sep 17 00:00:00 2001 From: GridCell Date: Mon, 20 Feb 2017 14:10:33 +0000 Subject: [PATCH] Updated snippets with blob metadata Use of correct map and return of the updated blob --- .../cloud/examples/storage/snippets/StorageSnippets.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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..80cf86ae4ad9 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,9 +314,11 @@ 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; }