FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

docs: Update DeleteObject Sample to be clearer on object versioning behavior by sydney-munro · Pull Request #2595 · googleapis/java-storage · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (1) .md  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

// [START storage_delete_file]
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

Expand All @@ -38,16 +39,19 @@ public static void deleteObject(String projectId, String bucketName, String obje
System.out.println("The object " + objectName + " wasn't found in " + bucketName);
return;
}

// 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);
BlobId idWithGeneration = blob.getBlobId();

JesseLovelace Jun 26, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

maybe add a comment on this line like "// The BlobId object has the Generation specified"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

i think the variable name is clear on this, no?

// Deletes the blob specified by its id. When the generation is present and non-null it will be

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think "when the generation is present" is a little vague, maybe we should specify as "When the generation is present in the BlobId object"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

rephrased the comments. let me know if that is clearer.

// specified in the request.
// If versioning is enabled on the bucket and the generation is present in the delete request,
// only the version of the object with the matching generation will be deleted.
// If instead you want to delete the current version, the generation should be dropped by
// performing the following.
// BlobId idWithoutGeneration =
// BlobId.of(idWithGeneration.getBucket(), idWithGeneration.getName());
Comment thread
sydney-munro marked this conversation as resolved.
// storage.delete(idWithoutGeneration);
storage.delete(idWithGeneration);

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

Back | FazBrowse Home | New Git URL