> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nami.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# 객체 헤드

> 객체의 메타데이터를 검색하는 방법

<Note>
  객체의 메타데이터를 검색하려면 해당 객체에 대한 READ 권한이 필요합니다.
</Note>

## 객체 헤드

HEAD 작업은 객체 자체를 반환하지 않고 객체의 메타데이터를 검색합니다. 이 작업은 객체의 메타데이터에만 관심이 있거나 객체의 존재 여부를 확인하려는 경우에 유용합니다.

### 기본 URL

```bash theme={null}
https://${bucketname}.storage.nami.cloud
```

### 매개변수

<ParamField path="objectKey" required>
  메타데이터를 검색할 객체의 키
</ParamField>

### 헤더

<ParamField header="If-Match" optional>
  ETag가 일치하는 경우에만 메타데이터를 반환합니다.
</ParamField>

<ParamField header="If-Modified-Since" optional>
  지정된 시간 이후에 객체가 수정된 경우에만 메타데이터를 반환합니다.
</ParamField>

### 요청 예제

<RequestExample>
  ```bash theme={null}
  curl -I "https://mybucket.storage.nami.cloud/example.jpg" \
    -H "Authorization: AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/20231028/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-date, Signature=fe5f80f77d5fa3beca038a248ff027d0445342fe2855ddc963176630326f1024"
  ```

  ```python theme={null}
  import boto3

  s3_client = boto3.client('s3',
      endpoint_url='https://storage.nami.cloud',
      aws_access_key_id='YOUR_ACCESS_KEY',
      aws_secret_access_key='YOUR_SECRET_KEY'
  )

  response = s3_client.head_object(
      Bucket='mybucket',
      Key='example.jpg'
  )

  print(f"Content Length: {response['ContentLength']}")
  print(f"Last Modified: {response['LastModified']}")
  print(f"ETag: {response['ETag']}")
  ```

  ```javascript theme={null}
  import { S3Client, HeadObjectCommand } from "@aws-sdk/client-s3";

  const client = new S3Client({
    endpoint: "https://storage.nami.cloud",
    credentials: {
      accessKeyId: "YOUR_ACCESS_KEY",
      secretAccessKey: "YOUR_SECRET_KEY",
    },
  });

  async function getObjectMetadata() {
    const command = new HeadObjectCommand({
      Bucket: "mybucket",
      Key: "example.jpg",
    });

    try {
      const response = await client.send(command);
      console.log("Content Length:", response.ContentLength);
      console.log("Last Modified:", response.LastModified);
      console.log("ETag:", response.ETag);
    } catch (err) {
      console.error("Error:", err);
    }
  }

  getObjectMetadata();
  ```

  ```go theme={null}
  package main

  import (
      "fmt"
      "github.com/aws/aws-sdk-go/aws"
      "github.com/aws/aws-sdk-go/aws/credentials"
      "github.com/aws/aws-sdk-go/aws/session"
      "github.com/aws/aws-sdk-go/service/s3"
  )

  func main() {
      sess := session.Must(session.NewSession(&aws.Config{
          Endpoint:    aws.String("https://storage.nami.cloud"),
          Region:      aws.String("us-east-1"),
          Credentials: credentials.NewStaticCredentials("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY", ""),
      }))

      s3Client := s3.New(sess)

      result, err := s3Client.HeadObject(&s3.HeadObjectInput{
          Bucket: aws.String("mybucket"),
          Key:    aws.String("example.jpg"),
      })
      if err != nil {
          panic(err)
      }

      fmt.Printf("Content Length: %d\n", *result.ContentLength)
      fmt.Printf("Last Modified: %v\n", *result.LastModified)
      fmt.Printf("ETag: %s\n", *result.ETag)
  }
  ```

  ```rust theme={null}
  use aws_sdk_s3::{Client, Config};
  use aws_config::credentials::StaticCredentialsProvider;
  use aws_types::region::Region;
  use tokio;

  #[tokio::main]
  async fn main() -> Result<(), Box<dyn std::error::Error>> {
      let credentials = StaticCredentialsProvider::new(
          "YOUR_ACCESS_KEY".to_string(),
          "YOUR_SECRET_KEY".to_string(),
          None,
      );

      let config = Config::builder()
          .endpoint_url("https://storage.nami.cloud")
          .region(Region::new("us-east-1"))
          .credentials_provider(credentials)
          .build();

      let client = Client::from_conf(config);

      let response = client
          .head_object()
          .bucket("mybucket")
          .key("example.jpg")
          .send()
          .await?;

      println!("Content Length: {}", response.content_length().unwrap());
      println!("Last Modified: {:?}", response.last_modified().unwrap());
      println!("ETag: {}", response.e_tag().unwrap());

      Ok(())
  }
  ```
</RequestExample>

### 응답 예제

```json theme={null}
HTTP/1.1 200 OK
x-amz-id-2: ef8yU9AS1ed4OpIszj7UDNEHGran
x-amz-request-id: 318BC8BC143432E5
Date: Wed, 28 Oct 2023 22:32:00 GMT
Last-Modified: Wed, 28 Oct 2023 19:27:20 GMT
ETag: "b9875f283e5571ae9ac762fba126cf8d"
Content-Length: 434234
Content-Type: image/jpeg
Server: Nami Cloud
```
