FileSystemManager.copyFileSync
收藏我的收藏
基础库 1.15.0 开始支持本方法,这是一个同步方法。
同步复制文件。
| 前提条件 | 无 |
| 业务背景 | 无 |
| 使用限制 | 无 |
| 注意事项 | 每个小程序的用户目录存储上限为 10M,不同小程序的用户目录相互隔离。 |
| 支持沙盒 | 否 |
| 相关教程 | 无 |
语法
FileSystemManager.copyFileSync(srcPath, destPath)
参数说明
srcPath
| 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
|---|---|---|---|---|
| string | 是 | 源文件地址 | 1.15.0 |
destPath
| 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
|---|---|---|---|---|
| string | 是 | 目标文件地址,必须以 ttfile://user 开头 | 1.15.0 |
返回值
无
错误码
| errorCode | errMsg | errorType | 说明 | 最低支持版本 |
|---|---|---|---|---|
| 109201 | permission denied, %s %s-> %s | D | 没有权限 请查看srcPath/destPath参数是否正确 | 1.15.0 |
| 109202 | operation not permitted, %s %s | D | 文 件路径读取后应该是一个文件 请查看srcPath参数是否正确 | 1.15.0 |
| 109203 | no such file or directory, %s %s-> %s | D | 目标路径或源文件不存在 请查看srcPath/destPath参数是否正确 | 1.15.0 |
| 109204 | user dir saved file size limit exceeded | D | 超过了可以保存的文件大小 | 1.15.0 |
| 161799 | no such file or directory, %s %s-> %s | D | srcPath参数为空 请查看srcPath参数是否正确 | 1.15.0 |
| 161799 | params srcPath is required | D | srcPath参数为空 请查看srcPath参数是否正确 | 1.15.0 |
| 161799 | params destpath is required | D | destpath参数为空 请查看destpath参数是否正确 | 1.15.0 |
扫码体验
请使用字节宿主APP扫码
代码示例
const fileSystemManager = tt.getFileSystemManager() // 下载网络资源 tt.downloadFile({ url: "https://s3.pstatp.com/toutiao/resource/developer/static/img/main-logo.8e3a839.png", success(res) { console.log("下载成功", res.tempFilePath) try { // 拷贝文件, destPath 目录必须以 `ttfile://user` 开头 fileSystemManager.copyFileSync(res.tempFilePath, `ttfile://user/logo.png`) console.log("拷贝成功") } catch (err) { console.log("拷贝失败", err) } }, fail(res) { console.log("下载失败", res.errMsg) }, })
