Skip to content

Commit

Permalink
JCLOUDS-1605: Return correct length in GCS getBlob
Browse files Browse the repository at this point in the history
Range requests could cause the payload size to be smaller than the
object size.
  • Loading branch information
gaul committed Nov 27, 2024
1 parent 44ec4b8 commit 6b51855
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,12 @@ public Blob getBlob(String container, String name, GetOptions options) {
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;
}

Expand Down

0 comments on commit 6b51855

Please sign in to comment.