
# 获取对象元数据
#### 功能说明
对指定桶中的对象发送HEAD请求，获取对象的元数据信息。
#### 方法定义
```
1. ObsClient->getObjectMetadata(array $parameter)
2. ObsClient->getObjectMetadataAsync(array $parameter, callable $callback)
```
#### 请求参数
| **字段名**       | **类型** | **约束** | **说明**                                           |
|:---|:---|:---|:---|
| Bucket        | string | 必选     | 桶名。                                              |
| Key           | string | 必选     | 对象名。                                             |
| VersionId     | string | 可选     | 对象的版本号。                                          |
| Origin        | string | 可选     | 预请求指定的跨域请求Origin（通常为域名）。                         |
| RequestHeader | string | 可选     | 跨域请求可以使用的HTTP头域。                                 |
| SseC          | string | 可选     | 以SSE-C方式解密对象，支持的值：AES256                         |
| SseCKey       | string | 可选     | SSE-C方式下解密的密钥，该密钥需要您自定义，并由256bit的密钥经过base64编码得到。 |
   
#### 返回结果
| **字段名**                 | **类型**            | **说明**                                                                                                                     |
|:---|:---|:---|
| HttpStatusCode          | integer           | HTTP状态码。                                                                                                                   |
| Reason                  | string            | HTTP文本描述。                                                                                                                  |
| RequestId               | string            | OBS服务端返回的请求ID。                                                                                                             |
| LastModified            | string            | 对象的最近一次修改时间。                                                                                                               |
| ContentLength           | integer           | 对象数据的长度。                                                                                                                   |
| ContentType             | string            | 对象的MIME类型，常见的contentType（MIME）列表参见[配置、编辑、查看对象元数据](https://support.huaweicloud.com/usermanual-obs/obs_03_0324.html)。        |
| ETag                    | string            | 对象的ETag值。                                                                                                                  |
| VersionId               | string            | 对象的版本号。                                                                                                                    |
| WebsiteRedirectLocation | string            | 当桶设置了Website配置，该参数指明对象的重定向地址。                                                                                              |
| StorageClass            | string            | 对象的存储类型，当对象存储类型是标准存储时，该值为空。                                                                                                |
| Restore                 | string            | 归档存储类型对象的恢复状态。                                                                                                             |
| AllowOrigin             | string            | 如果请求中的Origin满足桶的CORS规则，则返回CORS规则中的AllowedOrigin。                                                                           |
| AllowHeader             | string            | 如果请求的RequestHeader满足桶的CORS规则，则返回CORS规则中的AllowedHeader。                                                                     |
| AllowMethod             | string            | 桶CORS规则中的AllowedMethod。                                                                                                    |
| ExposeHeader            | string            | 桶CORS规则中的ExposeHeader。                                                                                                     |
| MaxAgeSeconds           | integer           | 桶CORS规则中的MaxAgeSeconds。                                                                                                    |
| SseKms                  | string            | SSE-KMS方式的算法。                                                                                                              |
| SseKmsKey               | string            | SSE-KMS加密方式下使用的KMS主密钥的ID值，为空则默认配置为默认密钥。密钥ID获取方法请参见[查看密钥](https://support.huaweicloud.com/usermanual-dew/dew_01_0179.html)。 |
| SseC                    | string            | SSE-C方式的算法。                                                                                                                |
| SseCKeyMd5              | string            | SSE-C方式的密钥的MD5值。                                                                                                           |
| Expiration              | string            | 对象的详细过期信息。                                                                                                                 |
| Metadata                | associative array | 对象自定义元数据。                                                                                                                  |
   
#### 代码样例
```
try {
       $resp = $obsClient->getObjectMetadata( [ 
              'Bucket' => 'bucketname',
              'Key' => 'objectkey'
       ] );
       printf ( "RequestId:%s\n", $resp ['RequestId'] );
       printf ( "ETag:%s\n", $resp ['ETag'] );
       printf ( "VersionId:%s\n", $resp ['VersionId'] );
       printf ( "ContentLength:%s\n", $resp ['ContentLength'] );
       printf ( "LastModified:%s\n", $resp ['LastModified'] );
       printf ( "Expiration:%s\n", $resp ['Expiration'] );
       printf ( "StorageClass:%s\n", $resp ['StorageClass'] );
} catch ( Obs\Common\ObsException $obsException ) {
       printf ( "ExceptionCode:%s\n", $obsException->getExceptionCode () );
       printf ( "ExceptionMessage:%s\n", $obsException->getExceptionMessage () );
}
```
