Skip to content

feat(Storage): Support user-provided hash validation in uploads#9178

Open
salilg-eng wants to merge 4 commits into
googleapis:mainfrom
salilg-eng:feat/hash-validation
Open

feat(Storage): Support user-provided hash validation in uploads#9178
salilg-eng wants to merge 4 commits into
googleapis:mainfrom
salilg-eng:feat/hash-validation

Conversation

@salilg-eng
Copy link
Copy Markdown
Contributor

This PR adds support for users to provide pre-calculated crc32c and md5 checksums during object uploads for server-side validation in the Google Cloud Storage client library.

Details:

Storage/src/Connection/Rest.php: Updated resolveUploadOptions to extract crc32c and md5 from top-level arguments. These are now mapped to the correct object metadata (crc32c and md5Hash) and also included in the X-Goog-Hash header if not already present. This ensures that the library skips auto-calculating hashes when the user provides them.
Storage/src/Bucket.php: Documented the new crc32c and md5 options in the docblocks for upload() and uploadAsync() methods.
Storage/tests/Unit/Connection/RestTest.php: Added unit tests (testInsertObjectWithUserProvidedHashes, testInsertObjectWithUserProvidedCrc32cOnly, and testInsertObjectWithUserProvidedMd5Only) to verify that providing these options works as expected and skips auto-calculation.
Storage/tests/System/UploadObjectsTest.php: Added system tests for both CRC32C and MD5 (both success and failure cases) to verify that GCS correctly validates or rejects uploads based on these top-level options.
Fixes: b/332673668

@salilg-eng salilg-eng requested review from a team as code owners May 11, 2026 06:11
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label May 11, 2026
Copy link
Copy Markdown
Collaborator

@Hectorhammett Hectorhammett left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants