# saveImageToLocal

> 保存图片到本地

### saveImageToLocal

> 保存图片到本地

#### 请求参数

| 参数           | 类型                          | 必填 | 说明                                    |
| -------------- | ----------------------------- | ---- | --------------------------------------- |
| `imageUrl`     | `string`                      | 否   | 图片网络地址（与 `encodedImage` 二选一） |
| `encodedImage` | `string`                      | 否   | 图片 base64（与 `imageUrl` 二选一）      |
| `success`      | `() => void`                  | 否   | 成功回调                                |
| `fail`         | `(error: BridgeCode) => void` | 否   | 失败回调                                |
| `complete`     | `() => void`                  | 否   | 完成回调                                |

#### 返回值

```js
Promise<void>
```

#### 异常返回值

```js
Promise<{ errCode: BridgeCode }>
```

#### 示例代码

```js
import { saveImageToLocal, BridgeCode } from '@kbapp/js-bridge'

saveImageToLocal({
    imageUrl: 'https://static.kaiba315.com.cn/kaiba-logo.png',
    success() {
        console.log('保存图片成功')
    },
    fail(error) {
        console.log('保存图片失败', error)
    },
})

saveImageToLocal({
    encodedImage: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...',
    success() {
        console.log('保存base64图片成功')
    },
})
```

> 支持 Promise 风格调用
