FileSystemManager.saveFile
Introduction
Save temporary files locally. This interface will move the temporary file, so after a successful call, the tempFilePath will no longer be available. You can only save from a temporary file to a local storage file.
Usage Limitations
Supported in the base library version 3.0.0
or higher.
Parameters
Object object
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
tempFilePath | string | Yes | Temporary storage file path (relative path) | |
filePath | string | Yes | Path to store the file (relative path) | |
success | function | No | Callback function for a successful API call | |
fail | function | No | Callback function for a failed API call | |
complete | function | No | Callback function for the end of the API call (executed for both successful and failed calls) |
object.success
Callback Function
Parameters
Object res
Attribute | Type | Description |
---|---|---|
savedFilePath | string | File path after successful storage (relative path) |
success | string | true-Set successfully |
object.fail Callback Function
Parameters
Object res
Attribute | Type | Description |
---|---|---|
errMsg | string | Error message |
success | string | false-Set failed |
errMsg Description
Error Message | Description |
---|---|
parameter error: F10001 | The original path or destination path parameter is null |
fail sdcard not mounted: F10002 | Android sdcard mount failed |
fail the maximum size of the file storage limit exceeded: F10004 | Insufficient storage space |
fail permission denied: F10005, open "${filePath}" | No write permission for the specified filePath path |
fail no such file or directory: F10007 "${filePath}" | Parent directory does not exist |
fail tempFilePath file not exist | The specified tempFilePath file cannot be found |
Sample Code
// pages/index/index.js
Page({
saveFile() {
const fs = dlt.getFileSystemManager();
fs.saveFile({
tempFilePath: 'xxx.png',
filePath: `${dlt.env.USER_DATA_PATH}/hello.png`,
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
},
});