> 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). Agents can also search and read this documentation through its [MCP server](https://developers-apps-in-toss.toss.im/~gitbook/mcp).

# 文件保存

### 保存文件

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