Skip to content

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

Closed
salilg-eng wants to merge 1 commit intogoogleapis:mainfrom
salilg-eng:feat/hash-validation
Closed

feat(Storage): Support user-provided hash validation in uploads#9164
salilg-eng wants to merge 1 commit intogoogleapis:mainfrom
salilg-eng:feat/hash-validation

Conversation

@salilg-eng
Copy link
Copy Markdown
Contributor

@salilg-eng salilg-eng commented May 5, 2026

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 5, 2026 13:30
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label May 5, 2026
@salilg-eng salilg-eng closed this May 5, 2026
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.

1 participant