From 6b5185536586cd89c9645c37052d60c4f6c60a73 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Wed, 27 Nov 2024 12:54:21 -0800 Subject: [PATCH] JCLOUDS-1605: Return correct length in GCS getBlob Range requests could cause the payload size to be smaller than the object size. --- .../blobstore/GoogleCloudStorageBlobStore.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java index b70749212a..d053581f32 100644 --- a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java @@ -250,10 +250,12 @@ public final class GoogleCloudStorageBlobStore extends BaseBlobStore { org.jclouds.http.options.GetOptions httpOptions = blob2ObjectGetOptions.apply(options); MutableBlobMetadata metadata = objectToBlobMetadata.apply(gcsObject); Blob blob = new BlobImpl(metadata); - // TODO: Does getObject not get the payload?! Payload payload = api.getObjectApi().download(container, Strings2.urlEncode(name), httpOptions).getPayload(); + long contentLength = payload.getContentMetadata().getContentLength(); payload.setContentMetadata(metadata.getContentMetadata()); // Doing this first retains it on setPayload. blob.setPayload(payload); + // getObject() returns the full object length but download() could be smaller due to range requests. + payload.getContentMetadata().setContentLength(contentLength); return blob; }