Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Update DeleteObject Sample to be clearer on object versioning behavior #2595

Merged
merged 7 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ If you are using Maven without the BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.41.0')
implementation platform('com.google.cloud:libraries-bom:26.42.0')

implementation 'com.google.cloud:google-cloud-storage'
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ public static void deleteObject(String projectId, String bucketName, String obje
System.out.println("The object " + objectName + " wasn't found in " + bucketName);
return;
}
// Permanently deletes a blob, even if object versioning is enabled.
// If object versioning is enabled you can use
// storage.delete(BlobId.of(bucketName, objectName));
// to mark an object as non-current
storage.delete(blob.getBlobId());
sydney-munro marked this conversation as resolved.
Show resolved Hide resolved

// Optional: set a generation-match precondition to avoid potential race
// conditions and data corruptions. The request to upload returns a 412 error if
// the object's generation number does not match your precondition.
Storage.BlobSourceOption precondition =
Storage.BlobSourceOption.generationMatch(blob.getGeneration());

storage.delete(bucketName, objectName, precondition);

System.out.println("Object " + objectName + " was deleted from " + bucketName);
System.out.println("Object " + objectName + " was permanently deleted from " + bucketName);
}
}
// [END storage_delete_file]
Loading