FileSystemManager.saveFile
简介
保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。仅可以从临时文件保存至本地存储文件。
使用限制
基础库 3.0.0 或更高版本支持。
参数
Object object
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| tempFilePath | string | 是 | 临时存储文件路径 (相对路径) | |
| filePath | string | 是 | 要存储的文件路径 (相对路径) | |
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
object.success 回调函数
参数
Object res
| 属性 | 类型 | 说明 |
|---|---|---|
| savedFilePath | string | 存储成功后的文件路径 (相对路径) |
| success | string | true-成功 |
object.fail 回调函数
参数
Object res
| 属性 | 类型 | 说明 |
|---|---|---|
| errMsg | string | 错误信息 |
| success | string | false-失败 |
errMsg 说明
| 错误信息 | 说明 |
|---|---|
| parameter error: F10001 | 原路径或目标路径参数为 null |
| fail sdcard not mounted: F10002 | Android sdcard 挂载失败 |
| fail the maximum size of the file storage limit exceeded: F10004 | 存储空间不足 |
| fail permission denied: F10005, open "${filePath}" | 指定的 filePath 路径没有写权限 |
| fail no such file or directory: F10007 "${filePath}" | 上级目录不存在 |
| fail tempFilePath file not exist | 指定的 tempFilePath 找不到文件 |
示例代码
// pages/index/index.js
Page({
saveFile() {
const fs = dlt.getFileSystemManager();
fs.saveFile({
tempFilePath: "xxx.png",
filePath: `${dlt.env.USER_DATA_PATH}/hello.png`,
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
},
});