📌 从基础库 3.125.4 版本开始支持
将临时文件保存到本地存储(移动操作,调用成功后临时文件将不可用)
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| tempFilePath | string | 是 | 临时文件路径(本地路径) | |
| filePath | string | 否 | 目标存储路径(不传则使用随机文件名) | |
| success | function | 否 | 成功回调 | |
| fail | function | 否 | 失败回调 | |
| complete | function | 否 | 完成回调 |
function saveFile(tempFilePath, filePath = '') {
const fs = xhs.getFileSystemManager()
fs.saveFile({
tempFilePath, // 临时存储文件路径
filePath, // 可选:要存储的文件路径
success: (res) => {
console.log('文件保存成功:', res.savedFilePath); // 存储后的文件路径
},
fail: (err) => {
console.error('文件保存失败:', err);
},
complete: () => {
console.log('文件保存操作完成');
}
});
}
// 调用示例
saveFile('/path/to/temp/file.txt');