Overview
This API uses a sync GET request to perform hash calculation and return a calculated hash value in real time.
Billing Description
Calling the API will incur hash calculation fees and COS read request fees as described in Request Fees. If the files are stored in COS STANDARD_IA storage class, calling the API will incur STANDARD_IA data retrieval fees as described in Data Retrieval Fees. Processing is not supported for files stored in the ARCHIVE or DEEP ARCHIVE storage classes. To process these files, you first need to restore them as instructed in POST Object restore. Restrictions
Request timeout period: 10 seconds
This API can be used in Beijing, Shanghai, Guangzhou, Chengdu, Hong Kong (China), Singapore, and Silicon Valley regions.
Request
Sample request
GET /for-test.mp4?ci-process=filehash&type=md5 HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
Date: <GMT Date>
Authorization: <Auth String>
Content-Length: <length>
Request parameters
The parameters are described as follows:
|
| Operation type. It is fixed at filehash for hash calculation. | | |
| Supported hash algorithm. Valid values: md5, sha1, sha256 | | |
| Whether to automatically add the calculated hash value to the custom header in the file. Format: x-cos-meta-md5/sha1/sha256 Valid values: true, false. If this parameter is left empty, it is false by default. | | |
Request body
This request does not have a request body.
Response
Response body
The response body returns application/xml data. The following contains all the nodes:
<Response>
<FileHashCodeResult>
<MD5>0fe771ba515b0525552f59290a50c0ef</MD5>
<FileSize>1048576</FileSize>
</FileHashCodeResult>
<Input>
<Bucket>test-1234567890</Bucket>
<Object>wg.txt</Object>
<Region>ap-chongqing</Region>
</Input>
</Response>
The nodes are described as follows:
Response has the following sub-nodes:
|
| | | |
| | Basic information of the input file | |
FileHashCodeResult has the following sub-nodes:
|
| Response.FileHashCodeResult | This field is returned if type in the request is md5. | |
| Response.FileHashCodeResult | This field is returned if type in the request is sha1. | |
| Response.FileHashCodeResult | This field is returned if type in the request is sha256. | |
| Response.FileHashCodeResult | | |
Input has the following sub-nodes:
|
| Response.JobsDetail.Input | | |
| Response.JobsDetail.Input | Bucket where the input file resides | |
| Response.JobsDetail.Input | Name of the input file in the bucket | |
Error codes
There are no specific error messages for this request operation. For common error messages, see Error Codes. Examples
Request
GET /for-test.mp4?ci-process=filehash&type=md5 HTTP/1.1
Host: test-1234567890.cos.ap-beijing.myqcloud.com
Authorization: q-sign-algorithm=sha1&q-ak=AKIDWtTCBYjM5OwLB9CAwA1Qb2ThTSUjfG****-sign-time=1484213027;32557109027&q-key-time=1484213027;32557109027&q-header-list=host&q-url-param-list=acl&q-signature=dcc1eb2022b79cb2a780bf062d3a40e120b4****
Content-Length: 0
Response
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 666
Connection: keep-alive
Date: Mon, 28 Jun 2022 15:23:12 GMT
Server: tencent-cos
x-cos-request-id: NTg3NzRiMjVfYmRjMzVfMTViMl82ZGZmNw==
<Response>
<FileHashCodeResult>
<MD5>0fe771ba515b0525552f59290a50c0ef</MD5>
<FileSize>1048576</FileSize>
<LastModified>2022-06-27T15:23:12+0800</LastModified>
<Etag>"ee8de918d05640145b18f70f4c3aa602"</Etag>
</FileHashCodeResult>
<Input>
<Bucket>test-1234567890</Bucket>
<Object>wg.txt</Object>
<Region>ap-chongqing</Region>
</Input>
</Response>