FileSystemManager.saveFile(Object object)
功能描述
保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
tempFilePath | string | 是 | 临时存储文件路径 (本地路径) | |
filePath | string | 是 | 要存储的文件路径 (本地路径) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
object.success 回调函数
参数
Object res
属性 | 类型 | 说明 |
---|---|---|
savedFilePath | string | 存储后的文件路径 (本地路径) |
示例代码
const fs = mgtv.getFileSystemManager()
// 选择图片后,保存到文件系统
mgtv.chooseImage({
count: 1,
sourceType: ['album'],
sizeType: ['compressed', 'original'],
success: (res) => {
const [path] = res.tempFilePaths
fs.saveFile({
tempFilePath: path,
filePath: `${mgtv.env.USER_DATA_PATH}/1.png`,
success: (res) => {
// 文件保存成功
console.log(res)
},
fail: (res) => {
console.error(res)
}
})
}
})