抖音开放平台Logo
开发者文档
控制台

FileSystemManager.copyFileSync
收藏
我的收藏

基础库 1.15.0 开始支持本方法,这是一个同步方法。

同步复制文件。

前提条件
业务背景
使用限制
注意事项
destPath 必须以 ttfile://user 开头。
相关教程

语法

FileSystemManager.copyFileSync(srcPath, destPath)

参数说明

srcPath

类型默认值必填说明最低支持版本
string
源文件地址
1.15.0

destPath

类型默认值必填说明最低支持版本
string
目标文件地址,必须以 ttfile://user 开头
1.15.0

返回值

错误码

errNoerrMsg说明最低支持版本
10401error stack
小游戏框架内部错误,有需要请创建工单咨询
1.15.0
21101permission denied, $apiName $srcPath -> $destPath
1.15.0
21102operation not permitted, $apiName $srcPath
1.15.0
21103no such file or directory, $apiName $srcPath -> $destPath
1.15.0
21104user dir saved file size limit exceeded
1.15.0
20000params $paramName is required
1.15.0
20000params $paramName type is not $paramType type
1.15.0
20000$paramName is invalid
1.15.0
21105operation failed
小游戏框架内部错误,有需要请创建工单咨询
1.15.0
20001invalid param
1.15.0
20000internal error
小游戏框架内部错误,有需要请创建工单咨询
1.15.0

代码示例

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); }, });