抖音开放平台Logo
控制台

FileSystemManager.unlink
收藏
我的收藏

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

删除文件,只能在 ttfile://user 开头的用户目录下操作。

前提条件
业务背景
使用限制
注意事项
开发者只能删除 用户目录(ttfile://user) 下的文件
相关教程

语法

FileSystemManager.unlink(options)

参数说明

options 为 object 类型,属性如下:

属性名类型默认值必填说明最低支持版本
filePathstring
要删除的文件路径, 必须以 ttfile://user 开头
1.15.0
successfunction
接口调用成功的回调函数
1.15.0
failfunction
接口调用失败的回调函数
1.15.0
completefunction
接口调用结束的回调函数(调用成功、失败都会执行)
1.15.0

回调成功

object 类型,属性如下:

属性名类型说明最低支持版本
errMsgstring
"FileSystemManager.unlink:ok"
1.15.0

回调失败

object 类型,属性如下:

属性名类型说明最低支持版本
errMsgstring
"FileSystemManager.unlink:fail" + 详细错误信息
1.15.0

错误码

errNoerrMsg说明最低支持版本
20000unlink:fail filePath is invalid
filePath 参数错误
1.99.0
20001unlink:fail param should be xxx, but got xxx
参数校验错误
1.99.0
21101unlink:fail permission denied, unlink {filePath_value}
文件路径不可写
1.99.0
21102unlink:fail no such file or directory, unlink {filePath_value}
文件不存在
1.99.0
21103unlink:fail operation not permitted, unlink {filePath_value}
非文件路径
1.99.0

代码示例

const fileSystemManager = tt.getFileSystemManager();

tt.chooseImage({
  success(res) {
    // 保存临时文件到 用户目录
    const savedFilePath = fileSystemManager.saveFileSync(res.tempFilePaths[0]);

    // 删除文件
    fileSystemManager.unlink({
      filePath: savedFilePath,
      success(_res) {
        console.log("删除成功");
      },
      fail(res) {
        console.log("删除失败", res.errMsg);
      },
    });
  },
});