> 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/api-and-sdk-zh/common/file-storage/file.md).

# 文件保存

### 保存文件

**SDK 函数：** `saveBase64Data`

`saveBase64Data` 该函数会将以字符串编码的 Base64 数据，使用指定的文件名和 MIME 类型保存到用户设备上。可以保存图片、文本、PDF 等多种格式的数据。

**签名**

```typescript
function saveBase64Data(params: SaveBase64DataParams): Promise<void>;
```

**参数**

* **params** · 必需 · `SaveBase64DataParams`

  这是一个包含要保存的数据和文件信息的对象。

  * **params.data** · 必需 · `string`

    这是以 Base64 格式编码的数据字符串。
  * **params.fileName** · 必需 · `string`

    这是要保存的文件名。还需要同时附上扩展名。例如，可以保存为 'example.png'。
  * **params.mimeType** · 必需 · `string`

    这是要保存的文件的 MIME 类型。例如，指定为 'image/png' 时是图片，'application/pdf' 是 PDF 文件。更多详情请参见 [MIME 文档](https://developer.mozilla.org/ko/docs/Web/HTTP/Guides/MIME_types)请参考。

**示例**

**将 Base64 图片数据保存到用户设备**

{% tabs %}
{% tab title="js" %}

```js
import { saveBase64Data } from '@apps-in-toss/web-framework';

async function handleSaveBase64Data() {
  try {
    await saveBase64Data({
      data: 'iVBORw0KGgo...',
      fileName: 'some-photo.png',
      mimeType: 'image/png',
    });
    console.log('数据保存成功');
  } catch (error) {
    console.error('数据保存失败：', error);
  }
}
```

{% endtab %}

{% tab title="React" %}

```tsx
import { saveBase64Data } from '@apps-in-toss/web-framework';
import { Button } from '@toss/tds-mobile';

function SaveButton() {
  const handleSave = async () => {
    try {
      await saveBase64Data({
        data: 'iVBORw0KGgo...',
        fileName: 'some-photo.png',
        mimeType: 'image/png',
      });
    } catch (error) {
      console.error('数据保存失败：', error);
    }
  };

  return <Button onClick={handleSave}>保存</Button>;
}
```

{% endtab %}

{% tab title="React Native" %}

```tsx
import { saveBase64Data } from '@apps-in-toss/framework';
import { Button } from '@toss/tds-react-native';

function SaveButton() {
  const handleSave = async () => {
    try {
      await saveBase64Data({
        data: 'iVBORw0KGgo...',
        fileName: 'some-photo.png',
        mimeType: 'image/png',
      });
    } catch (error) {
      console.error('数据保存失败：', error);
    }
  };

  return <Button onPress={handleSave}>保存</Button>;
}
```

{% endtab %}
{% endtabs %}


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/common/file-storage/file.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
