You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Blob.reload() does not work as intuitively expected #149
But doc is silent on how to renew the blob object, which is a bit tricky because neither blob.reload() nor storage.getBlob(blob.getBlobId()) does not help. Behavior varies depending on versioning setting for the bucket.
If versioning is enabled:
Attempt to reload as recommended: blob.reload(Blob.BlobSourceOption.generationNotMatch()) causes StorageException '304 Not Modified'
blob.reload() returns the same blob. storage.get(blob.getBlobId()) returns the same blob (that seems very confusing).
And only storage.get(blobId) returns the updated blob.
If versioning is Suspended:
before upload: blob.getContent() returns an empty array
After upload: blob.getContent() throws StorageException: 404 Not Found , No such object storage.get(blob.getBlobId()), blob.reload() and blob.reload(Blob.BlobSourceOption.generationNotMatch()) return null.
And again only storage.get(blobId) returns the updated blob.
For those who want to play around with it:
Setting versioning on a bucket with gsutil: #> gsutil versioning set on gs://bucket_versioning_on #> gsutil versioning set off gs://bucket_versioning_off
changed the title [-]WriterChannel does not update blob's information when upload has finished[/-][+]WriteChannel does not update blob's information when upload has finished[/+]on Mar 23, 2020
changed the title [-]WriteChannel does not update blob's information when upload has finished[/-][+]Blob.reload() does not as intuitively expected[/+]on May 8, 2020
Blob.reload() is just a shortcut method for Storage.get(BlobId). BlobId includes bucket,name and generation. If generation is not specified Storage.get(blobId) returns the latest version. If generation is given and differs from the latest version the output depends on the versioning setting of the bucket: If versioning is enabled Storage.get(BlobId) returns not the latest version, if disabled then null is returned, which means: 'object not found'. Blob.reload() always use generation, so if the content is changed reload() will never return the latest version. Such behavior is not intuitively expected.
Possible fix is to make Blob.reload() to not include generation in the get request.
Activity
dmitry-fa commentedon Feb 26, 2020
For those who want to play around with it:
Setting versioning on a bucket with gsutil:
#> gsutil versioning set on gs://bucket_versioning_on#> gsutil versioning set off gs://bucket_versioning_offThe code:
[-]WriterChannel does not update blob's information when upload has finished[/-][+]WriteChannel does not update blob's information when upload has finished[/+][-]WriteChannel does not update blob's information when upload has finished[/-][+]Blob.reload() does not as intuitively expected[/+]dmitry-fa commentedon May 8, 2020
Blob.reload() is just a shortcut method for Storage.get(BlobId). BlobId includes bucket,name and generation. If generation is not specified Storage.get(blobId) returns the latest version. If generation is given and differs from the latest version the output depends on the versioning setting of the bucket: If versioning is enabled Storage.get(BlobId) returns not the latest version, if disabled then null is returned, which means: 'object not found'. Blob.reload() always use generation, so if the content is changed reload() will never return the latest version. Such behavior is not intuitively expected.
Possible fix is to make Blob.reload() to not include generation in the get request.
[-]Blob.reload() does not as intuitively expected[/-][+]Blob.reload() does not work as intuitively expected[/+]elharo commentedon May 12, 2020
What URL does that sample code come from? It has an issue.
dmitry-fa commentedon May 12, 2020
Which sample code do you mean?
elharo commentedon May 12, 2020
byte[] content = "Hello, World!".getBytes(UTF_8);
try (WriteChannel writer = blob.writer()) {
try {
writer.write(ByteBuffer.wrap(content, 0, content.length));
} catch (Exception ex) {
// handle exception
}
}
dmitry-fa commentedon May 12, 2020
https://googleapis.dev/java/google-cloud-storage/latest/com/google/cloud/storage/Blob.html#writer-com.google.cloud.storage.Storage.BlobWriteOption...-