> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/sdk/domains-api/device/device.opencamera.md). Agents can also search and read this documentation through its [MCP server](https://developers-apps-in-toss.toss.im/~gitbook/mcp).

# Device.openCamera

> 함수형 API `openCamera`로도 같은 기능을 쓸 수 있어요.

### 기능 설명

카메라를 열고, 사용자가 촬영한 이미지를 반환해요.

카메라 권한이 거부되면 에러가 발생해요. `Device.openCamera.getPermission()`으로 권한을 확인하고 `Device.openCamera.openPermissionDialog()`로 권한을 요청할 수 있어요.

### 타입

```ts
Device.openCamera(options?: OpenCameraOptions): Promise<ImageResponse>;
```

**Params**

```ts
type OpenCameraOptions = {
  /** 이미지를 Base64로 반환할지 여부예요. 기본값은 false예요. */
  base64?: boolean;
  /** 이미지의 최대 너비(px)예요. 기본값은 1024예요. */
  maxWidth?: number;
};
```

**Response**

```ts
type ImageResponse = {
  id: string;
  dataUri: string;
};
```

### 에러

호출이 실패하면 Promise가 reject돼요. 에러는 `try`/`catch`로 처리해요. 미니앱 사용 권한 에러는 `error instanceof OpenCameraPermissionError`로 확인하고, 코드가 있는 에러는 `error.code`로 구분해요. 에러 클래스는 `@apps-in-toss/web-framework`에서 import할 수 있어요.

토스 앱 버전별 에러는 다음과 같아요.

| 토스 앱 버전    | 운영체제        | 에러 클래스 또는 `error.code`      | 설명                                    |
| ---------- | ----------- | --------------------------- | ------------------------------------- |
| 모든 지원 버전   | Android·iOS | `OpenCameraPermissionError` | 미니앱의 카메라 사용 권한이 거부됐어요.                |
| 모든 지원 버전   | Android·iOS | `CANCELED`                  | 촬영을 취소했거나 촬영을 완료하지 못했어요.              |
| 5.285.0 미만 | Android·iOS | `NOT_ALLOWED`               | 접근이 허용되지 않았어요. 기기 설정의 토스 앱 권한을 확인하세요. |
| 5.285.0 이상 | Android·iOS | `PERMISSION_DENIED`         | 미니앱 사용 동의가 거부됐거나 동의 창이 닫혔어요.          |
| 5.285.0 이상 | Android·iOS | `OS_PERMISSION_DENIED`      | 기기 설정에서 토스 앱의 접근 권한이 허용되지 않았어요.       |

### 예시 코드

```js
import { Device, OpenCameraPermissionError } from "@apps-in-toss/web-framework";

const base64 = true;

async function captureAndShow() {
  try {
    const image = await Device.openCamera({ base64, maxWidth: 1024 });

    const img = document.getElementById("preview");
    img.src = base64
      ? "data:image/jpeg;base64," + image.dataUri
      : image.dataUri;
  } catch (error) {
    if (error?.code === "CANCELED") {
      return;
    }

    if (
      error instanceof OpenCameraPermissionError ||
      error?.code === "PERMISSION_DENIED" ||
      error?.code === "OS_PERMISSION_DENIED" ||
      error?.code === "NOT_ALLOWED"
    ) {
      console.warn("카메라 권한이 없어요.");
      return;
    }
    console.error(error);
  }
}

document
  .getElementById("open-camera")
  .addEventListener("click", captureAndShow);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers-apps-in-toss.toss.im/documentation/sdk/domains-api/device/device.opencamera.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
