[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-05 UTC。"],[],[],null,["# Data validation and change detection\n\nCloud Storage encourages you to validate the data you transfer\nto and from your buckets. This page describes best practices for performing\nvalidations using either [CRC32C or MD5 checksums](/storage/docs/metadata#checksums) and describes the change\ndetection algorithm used by the `gcloud storage rsync` command.\n\nProtect against data corruption by using hashes\n-----------------------------------------------\n\nThere are a variety of ways that data can be corrupted while uploading to or\ndownloading from the Cloud:\n\n- Memory errors on client or server computers, or routers along the path\n- Software bugs (e.g., in a library that customers use)\n- Changes to the source file when an upload occurs over an extended period of time\n\nCloud Storage supports two types of hashes you can use to check the integrity\nof your data: CRC32C and MD5. CRC32C is the recommended validation method\nfor performing integrity checks. Customers that prefer MD5 can use that hash,\nbut MD5 hashes are [not supported for all objects](/storage/docs/metadata#md5).\n\n### Client-side validation\n\nYou can perform a integrity check for downloaded data by hashing the data on the\nfly and comparing your results to the server-supplied checksums. Note, however,\nthat the server-supplied checksums are based on the complete object as it's\nstored in Cloud Storage, which means the following types of downloads\ncan't be validated using the server-supplied hashes:\n\n- Downloads which undergo [decompressive transcoding](/storage/docs/transcoding), because the\n server-supplied checksum represents the object in its compressed state, while\n the served data has compression removed and consequently a different hash\n value.\n\n- A response that contains only a [portion of the object data](/storage/docs/downloading-objects#downloading-an-object-portion), which occurs\n when making a `range` request. Cloud Storage recommends using range\n requests only for restarting the download of a full object after the last\n received offset, because in that case you can compute and validate the\n checksum when the full download completes.\n\nIn cases where you can validate the download using checksums, you should discard\ndownloaded data with incorrect hash values and use the\n[recommended retry logic](/storage/docs/retry-strategy) to retry the request.\n\n### Server-side validation\n\nCloud Storage performs server-side validation in the following cases:\n\n- When you perform a copy or rewrite request within Cloud Storage.\n\n- When supplying an object's expected MD5 or CRC32C hash in an upload request.\n Cloud Storage only creates the object if the hash you provide matches the\n value Cloud Storage calculates. If it does not match, the request is\n rejected with a `BadRequestException: 400` error.\n\n - In applicable JSON API requests, you supply checksums as part of the\n [objects resource](/storage/docs/json_api/v1/objects).\n\n - In applicable XML API requests, you supply checksums using the\n [`x-goog-hash` header](/storage/docs/xml-api/reference-headers#xgooghash). The XML API also accepts the standard HTTP\n [Content-MD5 header](/storage/docs/xml-api/reference-headers#contentmd5) (see the [specification](https://datatracker.ietf.org/doc/html/rfc1864#section-2)).\n\n - Alternatively, you can perform client-side validation of your uploads by\n issuing a request for the uploaded object's metadata, comparing the\n uploaded object's hash value to the expected value, and deleting the\n object in case of a mismatch. This method is useful if the object's MD5 or\n CRC32C hash isn't known at the start of the upload.\n\nIn the case of [parallel composite uploads](/storage/docs/parallel-composite-uploads), users should perform an\nintegrity check for each component upload and then use [preconditions](/storage/docs/request-preconditions) with\ntheir compose requests to protect against race conditions. Compose requests\ndon't perform server-side validation, so users who want an end-to-end integrity\ncheck should perform client-side validation on the new composite object.\n\n### Google Cloud CLI validation\n\nFor the [Google Cloud CLI](/sdk/gcloud/reference/storage), data copied to or from a Cloud Storage\nbucket is validated. This applies to `cp`, `mv`, and `rsync` commands. If the\nchecksum of the source data does not match the checksum of the destination data,\nthe gcloud CLI deletes the invalid copy and prints a warning message.\nThis very rarely happens. If it does, you should retry the operation.\n\nThis automatic validation occurs after the object itself is finalized, so\ninvalid objects are visible for 1-3 seconds before they're identified and\ndeleted. Additionally, there is a chance that the gcloud CLI could be\ninterrupted after the upload completes but before it performs the validation,\nleaving the invalid object in place. These issues can be avoided when uploading\nsingle files to Cloud Storage by using [server-side validation](#server-validation),\nwhich occurs when using the `--content-md5` flag.\n| **Note:** The `--content-md5` flag is ignored for [objects that don't have an MD5 hash](/storage/docs/metadata#md5).\n\nChange detection for `rsync`\n----------------------------\n\nThe [`gcloud storage rsync`](/sdk/gcloud/reference/storage/rsync) command can also use MD5 or CRC32C checksums to\ndetermine if there is a difference between the version of an object found at the\nsource and the version found at the destination. The command compares checksums\nin the following cases:\n\n- The source and destination are both cloud buckets and the object has an\n MD5 or CRC32C checksum in both buckets.\n\n- The object does not have a file modification time (`mtime`) in either the\n source or destination.\n\nIn cases where the relevant object has an `mtime` value in both the source and\ndestination, such as when the source and destination are file systems, the\n`rsync` command compares the objects' size and `mtime`, instead of using\nchecksums. Similarly, if the source is a cloud bucket and the destination is a\nlocal file system, the `rsync` command uses the time created for the source\nobject as a substitute for `mtime`, and the command does not use checksums.\n\nIf neither `mtime` nor checksums are available, `rsync` only compares file sizes\nwhen determining if there is a change between the source version of an object\nand the destination version. For example, neither `mtime` nor checksums are\navailable when comparing [composite objects](/storage/docs/composite-objects) with objects at a cloud provider\nthat doesn't support CRC32C, because composite objects don't have MD5 checksums.\n\nWhat's next\n-----------\n\n- Explore [upload and download options](/storage/docs/uploads-downloads) for Cloud Storage.\n- Learn about [retry strategies](/storage/docs/retry-strategy) for Cloud Storage."]]